Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Passing contents of a cell to a macro

I am creating a worksheet model which will be used repetitively. I have the
macro to start the new worksheet and pre-fill some of the cells. After
manually completing the rest of the information on the worksheet, I want to
run a macro which will save that worksheet to a filename that exists in one
of the cells.

Here is the SaveAs Filename macro:

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\myusername\My Documents\filename.xls",
FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

I want to be able to replace "filename" with the value in cell A5 for
instance.

How can I do this?

Thank you.
Learning In Florida
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default Passing contents of a cell to a macro

mycellfilename=Range("A5").Value

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\myusername\My Documents\" &
mycellfilename & ".xls",
FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

--
If this posting was helpful, please click on the Yes button.
Regards,

Michael Arch.




"LivingIn32751" wrote:

I am creating a worksheet model which will be used repetitively. I have the
macro to start the new worksheet and pre-fill some of the cells. After
manually completing the rest of the information on the worksheet, I want to
run a macro which will save that worksheet to a filename that exists in one
of the cells.

Here is the SaveAs Filename macro:

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\myusername\My Documents\filename.xls",
FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

I want to be able to replace "filename" with the value in cell A5 for
instance.

How can I do this?

Thank you.
Learning In Florida

  #3   Report Post  
Posted to microsoft.public.excel.programming
Ken Ken is offline
external usenet poster
 
Posts: 207
Default Passing contents of a cell to a macro


Try range("A1").value if the path and filename are in the cell. If
only the filename is in the cell, you can probably use something like:

"C:\Documents and Settings\myusername\My Documents\" &
range('A1").value

This all presumes the filename is in cell A1 of the active sheet. You
could make the code more robust by naming the cell containing the
filename and referencing it by name rather than address. Something
like:

"C:\Documents and Settings\myusername\My Documents\" &
range('filename")

where filename is the name of the cell with the filename.

Good luck.

Ken
Norfolk, Va



On Sep 11, 12:36 pm, LivingIn32751
wrote:
I am creating a worksheet model which will be used repetitively. I have the
macro to start the new worksheet and pre-fill some of the cells. After
manually completing the rest of the information on the worksheet, I want to
run a macro which will save that worksheet to a filename that exists in one
of the cells.

Here is the SaveAs Filename macro:

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\myusername\My Documents\filename.xls",
FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

I want to be able to replace "filename" with the value in cell A5 for
instance.

How can I do this?

Thank you.
Learning In Florida



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Passing contents of a cell to a macro

Both answers I have received LOOK good, but they don't seem to be working.
I'm getting "expression expected" errors. I suspect the concatenation
character. Perhaps I need more quotes or parentheses, but try as I may, I'm
not getting past the errors. I've eliminated the spaces between the
concatenated operands to no avail. I've added parens to no avail. Should I
be using single of double quotes? 'Tis a puzzlement!
--
Learning In Florida


"Ken" wrote:


Try range("A1").value if the path and filename are in the cell. If
only the filename is in the cell, you can probably use something like:

"C:\Documents and Settings\myusername\My Documents\" &
range('A1").value

This all presumes the filename is in cell A1 of the active sheet. You
could make the code more robust by naming the cell containing the
filename and referencing it by name rather than address. Something
like:

"C:\Documents and Settings\myusername\My Documents\" &
range('filename")

where filename is the name of the cell with the filename.

Good luck.

Ken
Norfolk, Va



On Sep 11, 12:36 pm, LivingIn32751
wrote:
I am creating a worksheet model which will be used repetitively. I have the
macro to start the new worksheet and pre-fill some of the cells. After
manually completing the rest of the information on the worksheet, I want to
run a macro which will save that worksheet to a filename that exists in one
of the cells.

Here is the SaveAs Filename macro:

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\myusername\My Documents\filename.xls",
FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

I want to be able to replace "filename" with the value in cell A5 for
instance.

How can I do this?

Thank you.
Learning In Florida




  #5   Report Post  
Posted to microsoft.public.excel.programming
Ken Ken is offline
external usenet poster
 
Posts: 207
Default Passing contents of a cell to a macro

Try declaring a variable, then building the filename into the
variable, and finally using the variable in the Activeworkbook.saveas
line. You can also get rid of a lot of parameters since you are using
the defaults. Something like:

Sub Macro1()

Dim fn As String
fn = "C:\Documents and Settings\myusername\My Documents\filename.xls"
ActiveWorkbook.SaveAs Filename:=fn

End Sub

You can use debug.print or a msgbox to verify that fn is a valid
filename and that it is what you want.

Good luck.

Ken




On Sep 11, 2:00 pm, LivingIn32751
wrote:
Both answers I have received LOOK good, but they don't seem to be working.
I'm getting "expression expected" errors. I suspect the concatenation
character. Perhaps I need more quotes or parentheses, but try as I may, I'm
not getting past the errors. I've eliminated the spaces between the
concatenated operands to no avail. I've added parens to no avail. Should I
be using single of double quotes? 'Tis a puzzlement!
--
Learning In Florida



"Ken" wrote:

Try range("A1").value if the path and filename are in the cell. If
only the filename is in the cell, you can probably use something like:


"C:\Documents and Settings\myusername\My Documents\" &
range('A1").value


This all presumes the filename is in cell A1 of the active sheet. You
could make the code more robust by naming the cell containing the
filename and referencing it by name rather than address. Something
like:


"C:\Documents and Settings\myusername\My Documents\" &
range('filename")


where filename is the name of the cell with the filename.


Good luck.


Ken
Norfolk, Va


On Sep 11, 12:36 pm, LivingIn32751
wrote:
I am creating a worksheet model which will be used repetitively. I have the
macro to start the new worksheet and pre-fill some of the cells. After
manually completing the rest of the information on the worksheet, I want to
run a macro which will save that worksheet to a filename that exists in one
of the cells.


Here is the SaveAs Filename macro:


ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\myusername\My Documents\filename.xls",
FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False


I want to be able to replace "filename" with the value in cell A5 for
instance.


How can I do this?


Thank you.
Learning In Florida- Hide quoted text -


- Show quoted text -



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
Macro to clear range contents when cell contents are changed by us Steve E Excel Programming 12 February 22nd 07 09:09 PM
Macro to paste in the active cell the contents of a cell from another file?? LarryB Excel Programming 3 June 12th 06 06:37 PM
VBA - Passing Cell Contents Into Comment ajocius[_9_] Excel Programming 13 July 30th 05 11:50 PM
Macro to remove contents of cell and move all other contents up one row adw223 Excel Discussion (Misc queries) 1 July 1st 05 03:57 PM
passing spreadsheet cell data to macro Neal[_3_] Excel Programming 5 August 12th 03 04:10 PM


All times are GMT +1. The time now is 08:33 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"