Thebatfink
Active Member
- Joined
- Apr 8, 2007
- Messages
- 410
Hi,
Know this is not exactly VBA but I guess the experts know their VB even more so than their VBA!
I used to do this within Excel, but I'm trying to move away and into VB 2010. To me the code seems very simple and was pretty easy to migrate from VBA but it keeps hitting an error.
It doesn't seem to want to save, I get the error 'The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))'
I've tried various other things like holding the SaveFileName minus the extension, not setting the fileformat in the save line.. Nothing seems to work which makes me think its something I've not set correctly in Studio or something ill defined (I do have Microsoft Excel 12.0 Object Library added as a reference to my project).
Any one able to offer any help?
Thanks!
Know this is not exactly VBA but I guess the experts know their VB even more so than their VBA!
I used to do this within Excel, but I'm trying to move away and into VB 2010. To me the code seems very simple and was pretty easy to migrate from VBA but it keeps hitting an error.
Code:
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim ExcelMasterPlan As Excel.Application = New Excel.Application
Dim FileName As String
Dim SaveFileName As String
FileName = "\\server\folder\MyMaster.xlsm"
SaveFileName = "\\server\folder\MyNewMaster.xlsm"
Dim wb As Excel.Workbook = ExcelMasterPlan.Workbooks.Open(FileName)
ExcelMasterPlan.Workbooks.Open(FileName)
Try
wb.SaveAs(SaveFileName, Excel.XlFileFormat.xlOpenXMLWorkbookMacroEnabled)
Catch
MsgBox("An error occured saving")
ExcelMasterPlan.Workbooks.Close()
ExcelMasterPlan.Quit()
End Try
End Sub
End Class
It doesn't seem to want to save, I get the error 'The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))'
I've tried various other things like holding the SaveFileName minus the extension, not setting the fileformat in the save line.. Nothing seems to work which makes me think its something I've not set correctly in Studio or something ill defined (I do have Microsoft Excel 12.0 Object Library added as a reference to my project).
Any one able to offer any help?
Thanks!
Last edited: