View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Rech Jim Rech is offline
external usenet poster
 
Posts: 2,718
Default filenames and workbooks

It's not a good idea to reference a workbook by its index number. Better to
set a workbook variable to each workbook as you open it and that's all you
need:

Dim MainWB as Workbook

Sub OpenMainWB()
Set MainWB = Workbooks.Open(path-to-workbook...)
End Sub

Then later you can use:

MainWB.Activate
MainWB.Close, etc.
MainWB.Worksheets("Summary").PrintOut

and you can always get other information like:

MainWB.Name
MainWB.FullName

To set a cell to a 'number' string either first change its number format to
Text, or precede it with an apostrophe:

With Range("A1")
.NumberFormat ="@"
.Value = "1."
End With

or

Range("A1").Value = "'1."

--
Jim
"Sonnich" wrote in message
oups.com...
| Hi all!
|
| I have 2 odd problems in a system where I open 2 more files and process
| data in the 2nd one.
|
| 1. when opening a file from a script in a excel file, I would asume,
| that they file opened would become workbook(2), but by some odd reason
| it becomes something else, and "myself" becomed workbook(2). This
| problem was not present a few days ago...
|
| 2. I have the filename including path, but how do I get the name (of
| that string) in order to do like this: workbook(filename)
| E..g I have c:\sdgfsda\safsd.xls and I only need the latter part
| "safsd.xls"
|
| 3. (bonus) how do I set a cell() to a number, but as it was a string?
| E.g. a number and a dot? ("1.")
|