Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Filename Issue


I am writing a program where I prompt the user to save as: filename.

Later on I want to reference that workbook and pull a few cells out o
it. If I new the file name I would write:

Workbooks("book1.xls).Sheets("Sheet1").Range("A1") .Value

but since I don't know the filename I don't know how to reference it.
I would think it would be something like:

Workbooks(filename).Sheets("Sheet1").Range("A1").V alue or something bu
it isn't working for me.

While the sheet is open should I do a "find root directory and fil
name" routine and some how name that "filename"?

Any help would be appreciated.

Zeroma

--
Zeroma
-----------------------------------------------------------------------
Zeroman's Profile: http://www.excelforum.com/member.php...fo&userid=1662
View this thread: http://www.excelforum.com/showthread.php?threadid=31495

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Filename Issue

Hi Zeroman,

Below is some code a wrote to remove formulas on all worksheets of an *.xls
file and save it as separate copy taking the name from the user. Maybe it
will give you the direction.
Regards,
KL

'--------------Macro Start------------------
Const PASSWORD = "password"

Sub CopyBookWitoutFormulas()
Dim s As Worksheet
Dim thisFile As String
Dim newFile As Variant

thisFile = ThisWorkbook.Name
newFile = Application.GetSaveAsFilename _
(thisFile, "Microsoft Excel Workbooks (*.xls),*.xls")

Select Case VarType(newFile)
Case vbBoolean
MsgBox "Operation Canceled!"
Case Else
Application.ScreenUpdating = False
For Each s In ThisWorkbook.Worksheets
With s
Select Case .ProtectionMode
Case True
.Activate
With .Cells
.Copy
.PasteSpecial xlPasteValues
End With
.Range("A1").Select
Case False
.Unprotect PASSWORD
.Activate
With .Cells
.Copy
.PasteSpecial xlPasteValues
End With
.Range("A1").Select
.Protect PASSWORD
End Select
Next s
Application.ScreenUpdating = True
On Error GoTo ErrorHandler
ActiveWorkbook.SaveAs Filename:= newFile
End Select
Exit Sub
ErrorHandler:
MsgBox "File has not been saved!"
End Sub
'--------------Macro End------------------

"Zeroman" wrote in message
...

I am writing a program where I prompt the user to save as: filename.

Later on I want to reference that workbook and pull a few cells out of
it. If I new the file name I would write:

Workbooks("book1.xls).Sheets("Sheet1").Range("A1") .Value

but since I don't know the filename I don't know how to reference it.
I would think it would be something like:

Workbooks(filename).Sheets("Sheet1").Range("A1").V alue or something but
it isn't working for me.

While the sheet is open should I do a "find root directory and file
name" routine and some how name that "filename"?

Any help would be appreciated.

Zeroman


--
Zeroman
------------------------------------------------------------------------
Zeroman's Profile:
http://www.excelforum.com/member.php...o&userid=16628
View this thread: http://www.excelforum.com/showthread...hreadid=314957



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Filename Issue

You can set a reference to the workbook in your code before you do the saveas

Dim Wb As Workbook
Set Wb = ActiveWorkbook

You can use this then
WB.Sheets("Sheet1").Range("A1").Value




--
Regards Ron de Bruin
http://www.rondebruin.nl


"Zeroman" wrote in message ...

I am writing a program where I prompt the user to save as: filename.

Later on I want to reference that workbook and pull a few cells out of
it. If I new the file name I would write:

Workbooks("book1.xls).Sheets("Sheet1").Range("A1") .Value

but since I don't know the filename I don't know how to reference it.
I would think it would be something like:

Workbooks(filename).Sheets("Sheet1").Range("A1").V alue or something but
it isn't working for me.

While the sheet is open should I do a "find root directory and file
name" routine and some how name that "filename"?

Any help would be appreciated.

Zeroman


--
Zeroman
------------------------------------------------------------------------
Zeroman's Profile: http://www.excelforum.com/member.php...o&userid=16628
View this thread: http://www.excelforum.com/showthread...hreadid=314957



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Filename Issue

after the saveas operation is complete, you can capture in
a string.

Dim z As String
z = ActiveWorkbook.Name


-----Original Message-----

I am writing a program where I prompt the user to save

as: filename.

Later on I want to reference that workbook and pull a few

cells out of
it. If I new the file name I would write:

Workbooks("book1.xls).Sheets("Sheet1").Range("A1" ).Value

but since I don't know the filename I don't know how to

reference it.
I would think it would be something like:

Workbooks(filename).Sheets("Sheet1").Range("A1"). Value or

something but
it isn't working for me.

While the sheet is open should I do a "find root

directory and file
name" routine and some how name that "filename"?

Any help would be appreciated.

Zeroman


--
Zeroman
----------------------------------------------------------

--------------
Zeroman's Profile: http://www.excelforum.com/member.php?

action=getinfo&userid=16628
View this thread:

http://www.excelforum.com/showthread...hreadid=314957

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Table Filename reference in Spreadsheet XML issue Mike Excel Discussion (Misc queries) 1 August 2nd 10 09:40 PM
Cell("filename") doesn't update to new filename when do save as. Louis Excel Worksheet Functions 2 March 22nd 07 07:27 PM
set filename to <filename-date on open bob engler Excel Worksheet Functions 2 July 13th 06 05:11 AM
Macro link issue when saving as new filename. John Tolman[_2_] Excel Programming 0 July 11th 04 12:06 PM
Saving filename same as import filename Matt Excel Programming 4 February 24th 04 03:01 PM


All times are GMT +1. The time now is 03:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"