Dragonsong42
New Member
- Joined
- Mar 16, 2009
- Messages
- 1
I am writing a Visual Basic 6 program, in which I would like to open an Excel file, loop through several worksheets, and set the value of a specific cell within the worksheet. My code looks more or less like this (some variables are declared prior to this code snapshot):
Dim objExcel As Object
Set objExcel = CreateObject("excel.application")
ConvDataPath = (Path & "\Converted Data\Converted_Data_XX.xls")
objExcel.Workbooks.Open FileName:=(ConvDataPath)
ConvData = "Converted_Data_XX.xls"
Shtname = Mysheet1
For k = 1 To 4
Shtname = (k & ", " & Shtname)
objExcel.Windows(ConvData).Activate
objExcel.Sheets(Shtname).Select
Range(A1).Select
Next k
The problem that I am having is that VB is not seeing the Range selection as a valid function when a sheet is selected. If I remove the line where I specify the sheet, the program stops having an issue with the Cell selection, but that's not an option for me. Placing "objExcel." before the "Range" doesn't fix my problem.
Has anyone heard of VB6 having a problem with this function when manipulating Excel data? I've used similar functions before in macros. I'm wondering if perhaps I'm missing some OLE files or something...
Any help is appreciated!
Dim objExcel As Object
Set objExcel = CreateObject("excel.application")
ConvDataPath = (Path & "\Converted Data\Converted_Data_XX.xls")
objExcel.Workbooks.Open FileName:=(ConvDataPath)
ConvData = "Converted_Data_XX.xls"
Shtname = Mysheet1
For k = 1 To 4
Shtname = (k & ", " & Shtname)
objExcel.Windows(ConvData).Activate
objExcel.Sheets(Shtname).Select
Range(A1).Select
Next k
The problem that I am having is that VB is not seeing the Range selection as a valid function when a sheet is selected. If I remove the line where I specify the sheet, the program stops having an issue with the Cell selection, but that's not an option for me. Placing "objExcel." before the "Range" doesn't fix my problem.
Has anyone heard of VB6 having a problem with this function when manipulating Excel data? I've used similar functions before in macros. I'm wondering if perhaps I'm missing some OLE files or something...
Any help is appreciated!