D
dbKemp
How do I create an instance of the VBA 'ThisWorkbook' so I can refer to it
later in code?
Having problem with this line of code I found in book 'From VBA to VSTO'
Dim thisWB As Excel.Workbook = CType(Globals.ThisWorkbook, Excel.Workbook)
I have tried it in form class & worksheet class and always get the following
error message:
System.InvalidCastException was unhandled by user code
Message="Unable to cast object of type 'ExcelWorkbook1.ThisWorkbook' to
type 'Microsoft.Office.Interop.Excel.Workbook'."
Source="ExcelWorkbook1"
StackTrace:
at ExcelWorkbook1.Form1.Form1_Load(Object sender, EventArgs e) in
C:\Documents and Settings\l222254\Local Settings\Application Data\Temporary
Projects\ExcelWorkbook1\Form1.vb:line 4
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
later in code?
Having problem with this line of code I found in book 'From VBA to VSTO'
Dim thisWB As Excel.Workbook = CType(Globals.ThisWorkbook, Excel.Workbook)
I have tried it in form class & worksheet class and always get the following
error message:
System.InvalidCastException was unhandled by user code
Message="Unable to cast object of type 'ExcelWorkbook1.ThisWorkbook' to
type 'Microsoft.Office.Interop.Excel.Workbook'."
Source="ExcelWorkbook1"
StackTrace:
at ExcelWorkbook1.Form1.Form1_Load(Object sender, EventArgs e) in
C:\Documents and Settings\l222254\Local Settings\Application Data\Temporary
Projects\ExcelWorkbook1\Form1.vb:line 4
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)