Saurabh.Gupta

The following works good, except for, when I open the saved copy it tries to load the Customization assembly.

Globals.ThisWorkbook.SaveCopyAs(absoluteFilePath)

I tried code to remove customization, but as per the code, no customization exists.

Any help, hugely appreciated!

If (ServerDocument.IsCustomized(absoluteFilePath)) Then 'false

ServerDocument.RemoveCustomization(absoluteFilePath)

End If

Tried this as well, to no avail.............

Dim sd As ServerDocument = Nothing

Try

sd = New ServerDocument(absoluteFilePath) 'Exception {"Unable to retrieve the manifest from the document."}

sd.AppManifest.Clear()

sd.Save()

Catch ex As Exception

Finally

If Not sd Is Nothing Then

sd.Close()

End If

End Try

-----------------------------------

Thanks,

sg@Lehman Bros.



Re: Visual Studio Tools for Office MergeWorkbook does not work, SaveCopyAs works.......... ideas?

Saurabh.Gupta

This works fine:

Globals.ThisWorkbook.SaveCopyAs(absoluteFilePath)

This fails with the exception below:

Globals.ThisWorkbook.MergeWorkbook(absoluteFilePath)

I do not understand why

System.Runtime.InteropServices.COMException was unhandled by user code

ErrorCode=-2146827284

Message="Exception from HRESULT: 0x800A03EC"

Source=""

StackTrace:

Server stack trace:

Exception rethrown at [0]:

at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

at Microsoft.Office.Interop.Excel._Workbook.MergeWorkbook(Object Filename)

at CSECapitalCompilationAutomatedExcel.VstoUtil.CopyWorkSheetsToHere(String absoluteFilePath) in C:\Visual Studio Projects\CSEReportingAutomation\SourceVSTOProject\VstoUtil.vb:line 146

at CSECapitalCompilationAutomatedExcel.ActionsPaneControl1.GetNewWorkSheets(String NewReportName, String NewReportDate) in C:\Visual Studio Projects\CSEReportingAutomation\SourceVSTOProject\ActionsPaneControl1.vb:line 667

at CSECapitalCompilationAutomatedExcel.ActionsPaneControl1.ActionsPaneControl1_Load(Object sender, EventArgs e) in C:\Visual Studio Projects\CSEReportingAutomation\SourceVSTOProject\ActionsPaneControl1.vb:line 153

at System.Windows.Forms.UserControl.OnLoad(EventArgs e)

at System.Windows.Forms.UserControl.OnCreateControl()

at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)

at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)

at System.Windows.Forms.Control.CreateControl()

at System.Windows.Forms.Control.SetVisibleCore(Boolean value)

Thanks for any thoughts,

sg@Lehman Bros.





Re: Visual Studio Tools for Office MergeWorkbook does not work, SaveCopyAs works.......... ideas?

Steve Hansen

Hi,

If you are attempting to do this from within the workbook, you can just use the RemoveCustomization method associated with ThisWorkbook:

Globals.ThisWorkbook.RemoveCustomization();

You use ServerDocument to do this from outside the workbook (with the file otherwise closed).

Regards,

Steve Hansen






Re: Visual Studio Tools for Office MergeWorkbook does not work, SaveCopyAs works.......... ideas?

Saurabh.Gupta

I do not wish to remove the customization from the current workbook, just from it's backup.

I create a copy of the current customized workbook, and then try to remove the custmoization from the copy, not from self.

Further, the lil awkward part is, when I try to access the "workbook copy" using a Console Applicatin\ServerDocument, it actually does not show any manifest information.

However, if I simply lauunch the "workbook copy" by a double-click, it tries to load the customization and fails.

Appreciate your taking time Steve.

Anyways,

I found a workaround, instead of creating a copy of the workbook, I create an empty workbook, and copy all the sheets from the current to the backup, and all works neat, especially since, I do not have code behind the worksheets (just behind the workbook).





Re: Visual Studio Tools for Office MergeWorkbook does not work, SaveCopyAs works.......... ideas?

Robert Green

Have you tried removing the customization first and then making a copy of the workbook using SaveAs That has always worked for me.

Also, if you are using an Actions Pane, you need to detach that as well before saving and then reattach it.

To detach: Me.ActionsPane.Clear or Globals.ThisWorkbook.ActionsPane.Clear

To reattach: Me.ActionsPane.Show or Globals.ThisWorkbook.ActionsPane.Show

Robert





Re: Visual Studio Tools for Office MergeWorkbook does not work, SaveCopyAs works.......... ideas?

Saurabh.Gupta

Thanks Robert,

I will try it out, my workaround is working for me now, sounds as a feasible tweak!
No good reason why it should be so though. Bug
Appreciate your time! Thanks again.





Re: Visual Studio Tools for Office MergeWorkbook does not work, SaveCopyAs works.......... ideas?

Ji Zhou ¨C MSFT

Hi Bros,

SaveCopyAs and MergeWorkbook are two different functions. They are designed to complete diffirent tasks. These instrutions are from MSDN about these two functions:

SaveCopyAs Method

Saves a copy of the workbook to a file but doesn't modify the open workbook in memory.

Syntax

expression.SaveCopyAs(Filename)

expression Required. An expression that returns a Workbook object.

Filename Required. Specifies the file name for the copy.

MergeWorkbook Method

Merges changes from one workbook into an open workbook.

Syntax

expression.MergeWorkbook(Filename)

expression Required. An expression that returns a Workbook object.

Filename Required String. The file name of the workbook that contains the changes to be merged into the open workbook.

So I think when you use the MergeWorkbook function. there must be a workbook file already in the absoluteFilePath.

Thanks

Ji






Re: Visual Studio Tools for Office MergeWorkbook does not work, SaveCopyAs works.......... ideas?

Saurabh.Gupta

True, there should be a workbook existing to merge, and actually there is one in my case.

I do a to SaveCopyAs create a backup

And then at a later time do MergeWorkbook to merge this backup(created above) into another spredsheet that I have.

No solution yet, nevertheless, really appreciate you taking time!

Thanks.





Re: Visual Studio Tools for Office MergeWorkbook does not work, SaveCopyAs works.......... ideas?

Ji Zhou ¨C MSFT

Hi Saurabh,

This results from the SaveCopyAs method does not copy the customization assembly. So when Mergering the new workbook, error comes up for not finding the customization assembly. I also find another thread raised by you which dedicated to the same question:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1629041&SiteID=1

So I am mergering these two thread for discussing this problem in future.

Thanks

Ji






Re: Visual Studio Tools for Office MergeWorkbook does not work, SaveCopyAs works.......... ideas?

Saurabh.Gupta

Well Ji,

It doesn't copy the customization assembly, and neither do I want it to. But why does it hold the reference to the assembly & try to load it, when opened.

And if it does hold the reference to the assembly, why can't I see it\remove it. (In my posts above, I have detailed my attempts at removal of the reference.)

Thanks,

Saurabh

P.s. Good to know MSFT guys are administering the forums closely. It's critical to!





Re: Visual Studio Tools for Office MergeWorkbook does not work, SaveCopyAs works.......... ideas?

Robert Green

Saurabh,

I'm trying to understand your scenario here. You have a workbook with a customization assembly. You want to create a copy of that and have that copy not load the customization. Where does the MergeWorkbook come in Are you calling MergeWorkbook in the same customization assembly as the SaveAs

Robert





Re: Visual Studio Tools for Office MergeWorkbook does not work, SaveCopyAs works.......... ideas?

Saurabh.Gupta

Robert,
Appreciate your time, I am too far ahead in the project with the workaround, doing well.
For the benefit of forum users,
Background to the Problem:
1. I have a Workbook with VSTO Based code behind.
2. From the Workbook, I do a SaveAs to create a WorkBook backup devoid of the VSTO code behind. A plain simple workbook.
3.
At a later point of time, I may choose to include one of the backups(an oridnary .xls) in my workbook, by doing
MergeWorkbook in the VSTO code-behind Workbook.
Problem:
Details in the mails above.

Alternative solution:
1. create an empty new workbook, copy worksheet by worksheet from the VSTO workbook to the regular empty workbook
2. To get back the workbook, do the same. Open the regualr workbook and copy sheets one after another to the WorkBook with VSTO code behind.


For further interest of the forum readers, I created an intresting VSTO based Excel solution.
My concept is - "Excel is the UI".
1. I use one Excel to manage, load, save to DB, backup & version to shared drive an assortment of different Excel Reports. Of course, there are more things.
2. There is code behind the Workbook only, the worksheets are regular worksheets pulled-in, backed-up etc.
3. Of course there is lot other stuff behind.
4. Why I did this - well if you have to cater to financial users, of 15 different departments and regions, who are Excel gurus & the same time, have data saved to DB, and well preserve all the weird other related data\charts etc, that they create in Excel. Well to add a sense of order to rather very dis-organized data management.



Folks, this is my last post to the topic, Thanks for your time.
The alternative posted here works neatly, except for a few lines of more code.





Re: Visual Studio Tools for Office MergeWorkbook does not work, SaveCopyAs works.......... ideas?

JommyChen

Hi Saurabh,

Mergeworkbook can only be used for SharedWorkbook, which is not support in VSTO.

However, it wasn't mentioned in the following MSDN link: http://msdn2.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.mergeworkbook.aspx

But you can have a try in both 2003 Excel VBA and 2007 Excel VBA to test "MergeWorkBook" method.

Here is a link for your reference:

http://www.nickhodge.co.uk/gui/toolsmenu/comparemerge.htm