Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 16044

Error : System.InvalidCastException: 'Conversion from string "Sheet1" to type 'Intege

$
0
0
Hello

I get the following error when implemeting to change the Worksheet Codename property

VBA Code
Code:

Dim Excl_App As Excel.Application
 Dim Excl_Wbook As Excel.Workbook
 Dim Excl_Sheet As Excel.Worksheet

Set Excl_Wbook = Workbooks.Open("C:\ABC\"Trial.xlsx")

Excl_App.Visible = True
Set Excl_Sheet = ActiveSheet

Excl_Wbook.VBProject.VBComponents("Sheet1").Name = "Trial1Sam"
Excl_Wbook.Sheets("Sheet1").Name = "SamD"

VBNET19 Code
Code:

Public Class Trial
Public Excl_App As New Microsoft.Office.Interop.Excel.Application()
Public wBK As Excel.Workbook

Sub SheetChangeTrial()
Dim VBProject As Microsoft.Vbe.Interop.VBProject
Dim VBComp As Microsoft.Vbe.Interop.VBComponent

Dim strFilename As String = "C:\ABC\Trial.xlsx"

Excl_App.Visible = True
wBK = Excl_App.Workbooks.Open(strFilename)
VBComp = wBK.VBProject.VBComponents("Sheet1").Name = "SheetTrial1Sam"

''Following Error on above Line
'System.InvalidCastException: 'Conversion from string "Sheet1" to type 'Integer' is not valid.
End Sub

Thanks
SamD
25 Thread 5: 892237

Viewing all articles
Browse latest Browse all 16044

Trending Articles