View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Sheeloo[_3_] Sheeloo[_3_] is offline
external usenet poster
 
Posts: 1,805
Default How to store a reference of a excel workbook in a variable in vbsc

Change

set wb=objExcel.Workbooks.OpenText
"C:\Scripts\Test1.txt",,,xlDelimited,,,,,,,True,", "

to

wb=objExcel.Workbooks.OpenText
("C:\Scripts\Test1.txt",,,xlDelimited,,,,,,,True," ,")

since
1. You are assigning the right hand side to wb...
2. objExcel.Workbooks.OpenText does not return an object... it is a BOOLEAN
method which returns True if the file is opened and False otherwise.



"Store a reference of a excel workbook" wrote:

Hi,

I am trying to open a csv text file in excel using vbscript or vba. See the
code below

Const xlDelimited = 1
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

set wb=objExcel.Workbooks.OpenText
"C:\Scripts\Test1.txt",,,xlDelimited,,,,,,,True,", "

The above code is throwing an error. if i do not use the "set wb" to store
the reference to the opened workbook it works fine. But i wanted to store the
reference to this opened file so that i can use it later.

Please help me to solve this problem.