Macro to save file at runtime - How to?

I am trying to write a macro to take a filename from a cell(I can do that) 
and store in  a variable. THen I want to save the current sheet into  a new 
Excel File(SAVE AS command). When I attempted to record the macro going 
through the menu commands, it recorded the following:

  ActiveWorkbook.SaveAs Filename:="C:\file.xls", FileFormat _
      :=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= 
_
      False, CreateBackup:=False

Now what I want is to insert the filename variable in place of the 
"C:\file.xls". Seemed pretty simple but it doesn't work.

Anythoughts on how to do this?

-- 

Mickey A 


0
2/14/2006 9:06:13 PM
excel 39879 articles. 2 followers. Follow

3 Replies
696 Views

Similar Articles

[PageSpeed] 59

  dim myFileName as string
  'something that changes myfilename to what you want here...
  myfilename="C:\folder\" & activesheet.range("a1").value & ".xls"

  ActiveWorkbook.SaveAs Filename:=myfilename, FileFormat _
      :=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
      False, CreateBackup:=False



Mickey A wrote:
> 
> I am trying to write a macro to take a filename from a cell(I can do that)
> and store in  a variable. THen I want to save the current sheet into  a new
> Excel File(SAVE AS command). When I attempted to record the macro going
> through the menu commands, it recorded the following:
> 
>   ActiveWorkbook.SaveAs Filename:="C:\file.xls", FileFormat _
>       :=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=
> _
>       False, CreateBackup:=False
> 
> Now what I want is to insert the filename variable in place of the
> "C:\file.xls". Seemed pretty simple but it doesn't work.
> 
> Anythoughts on how to do this?
> 
> --
> 
> Mickey A

-- 

Dave Peterson
0
petersod (12004)
2/14/2006 9:17:15 PM
Thanks that worked. That is exactly what I did yesterday or so I thought. 
But today is a new day. I had to work around the file replace dialog by 
killing the file first.

Thanks again.


"Dave Peterson" <petersod@verizonXSPAM.net> wrote in message 
news:43F248DB.2FA4AD61@verizonXSPAM.net...
  dim myFileName as string
  'something that changes myfilename to what you want here...
  myfilename="C:\folder\" & activesheet.range("a1").value & ".xls"

  ActiveWorkbook.SaveAs Filename:=myfilename, FileFormat _
      :=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= 
_
      False, CreateBackup:=False



Mickey A wrote:
>
> I am trying to write a macro to take a filename from a cell(I can do that)
> and store in  a variable. THen I want to save the current sheet into  a 
> new
> Excel File(SAVE AS command). When I attempted to record the macro going
> through the menu commands, it recorded the following:
>
>   ActiveWorkbook.SaveAs Filename:="C:\file.xls", FileFormat _
>       :=xlNormal, Password:="", WriteResPassword:="", 
> ReadOnlyRecommended:=
> _
>       False, CreateBackup:=False
>
> Now what I want is to insert the filename variable in place of the
> "C:\file.xls". Seemed pretty simple but it doesn't work.
>
> Anythoughts on how to do this?
>
> --
>
> Mickey A

-- 

Dave Peterson 


0
2/15/2006 2:22:25 PM
You can kill the existing file or you could just stop the warning:

application.displayalerts=false
your code to save the file
application.displayalerts=true



Mickey A wrote:
> 
> Thanks that worked. That is exactly what I did yesterday or so I thought.
> But today is a new day. I had to work around the file replace dialog by
> killing the file first.
> 
> Thanks again.
> 
> "Dave Peterson" <petersod@verizonXSPAM.net> wrote in message
> news:43F248DB.2FA4AD61@verizonXSPAM.net...
>   dim myFileName as string
>   'something that changes myfilename to what you want here...
>   myfilename="C:\folder\" & activesheet.range("a1").value & ".xls"
> 
>   ActiveWorkbook.SaveAs Filename:=myfilename, FileFormat _
>       :=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=
> _
>       False, CreateBackup:=False
> 
> Mickey A wrote:
> >
> > I am trying to write a macro to take a filename from a cell(I can do that)
> > and store in  a variable. THen I want to save the current sheet into  a
> > new
> > Excel File(SAVE AS command). When I attempted to record the macro going
> > through the menu commands, it recorded the following:
> >
> >   ActiveWorkbook.SaveAs Filename:="C:\file.xls", FileFormat _
> >       :=xlNormal, Password:="", WriteResPassword:="",
> > ReadOnlyRecommended:=
> > _
> >       False, CreateBackup:=False
> >
> > Now what I want is to insert the filename variable in place of the
> > "C:\file.xls". Seemed pretty simple but it doesn't work.
> >
> > Anythoughts on how to do this?
> >
> > --
> >
> > Mickey A
> 
> --
> 
> Dave Peterson

-- 

Dave Peterson
0
petersod (12004)
2/15/2006 2:38:56 PM
Reply:

Similar Artilces:

Excedl 2003 / How to automize file opening
Hello Everyone below, my issue with excel 2003: When opening my "mainfile.xls", I wish it could open others "datafileS.xls", needed for my calculation within "mainfile.xls". All files are located in the same directory. a. mainfile.xls b. datafile1.xls c. datafile2.xls d. datafile3.xls In "mainfile.xls", I do use function such as INDIRECT("Datafile1.xls.....), to calculate various figures using my data files. My main problem is that if all my "datafileS.xls" are not opened when launching "mainfile.xls", this one cannot ret...

Macro warning with no macros
I have a workbook that when I try to open it I get the warning tellin me it contains macros and asking whether I want to Enable or Disabl them. I put no macros, no VB scripts, nothing at all in the workboo other than standard Excel formulas and some charts. I developed it i Excel 2002, SP-2, but have moved it back and forth between tw computers, the other which has Excel 97. Regardless of whether Enable or Disable or change the security settings so as not to get th warning, once the workbook is open even if I go t Tools-Macro-Macros... it lists no macros. How can I find out what's cau...

Where do I find "save as..." in MS Office 2007 ?
Sorry, but I did not found "save as..." menu in Office 2007. I only found in the upper left corner a flopy icon which represent a "save" but not a "save as...." So where is "save as..." (with files selction dialog) hidden in Office 2007? Camille Click the Office button (the round "pizza icon" in the upper left corner of the screen) and then click Save As. -- Stefan Blom Microsoft Word MVP "Camille Petersen" <cpet_magnus@hotmail.com> wrote in message news:4baf94cc$0$6768$9b4e6d93@newsspool3.arcor-onlin...

Best way to play Video files on an Access form?
Hello, My client has an Access front end with an SQL Server back end that will be storing Videos. The client wants to play those videos on an Access form. I know I can use Windows Media Player, but just wondering if anyone has experience doing this that has some insight on what the best way to handle this is. I know Media Player can be a bit of a pig, so if there is a better solution, I would love to hear it. Thanks! Rico ...

Locating a file in excel with a partial file name. #2
I have been runnimg with Office 2000 with which when I go to open a file in excel I am able to enter a partial file name, any part of the file name, to search for the file I wish to open. I am finding in Excel 2002 this function does not apprear to exsit, only the function where it will search for the fille that starts with what your typing will appear once its narrowed it down to the first of a few possible options. I require the ability to be able to just go to the file open icon in excel and on the file name line be able to typr the last few chararacters of a file name to find the ...

saving the history of recently used excel documentsto another comp
Reimaging a computer and wanting to know if I can export the excel history to the new image. Most files are on the network and not sure where they are, don't want to remap them all If you're referring to the files listed at the bottom of the File menu you'd have to run the Regedit program and go to this key: HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Recent Files replacing the "11.0" with your Excel version if different. Then you would have to right click on the Recent Files folder and Export it. After the reimage you would double-click the resultin...

Macro
Can anybody tell me how to kick off a macro automatically as file is opened? Regards ...

Convert old PPT file
My company recently upgrade the office 2003 to office 2007. It works well for most of the users except one. He had thousands of old powerpoint slides which created around year 1996,1997. By using right click to check the file properties, it shows the the application name is 'Microsoft Powerpoint 4.0' .These file can be opened by powerpoint 2003 but can not being opened by powerpoint 2007. Does anyone have idea how I can bulk convert those files to powerpoint 2003 format? Thanks James Steve has a macro here http://www.pptfaq.com/FAQ00740.htm -- john ATSIGN PPTAl...

When changing end time in appointment crm cannot save duration
Hello all When we started running the crm with https instead of http the following error appeared: When you change the end time of an appointment, CRM cannot save the change to duration. Error message: "Microsoft CRM was unable to save the change to duration. Try changing the duration value again." Any ideas? Regards Magnus Also, the error is only surfacing in the web client. /Magnus "Magnus Olsson" wrote: > Hello all > > When we started running the crm with https instead of http the following > error appeared: When you change the end time of an app...

generating .csv file
Hi, Is there any process (Code) to generate .csv files to all entities in MSCRM at a time. regards, sailaja. I think you are not clear with question. 1. You can export data to .csv file or excel file from any entity 2. You can export customization to .xml file which are enttities list etc. -- Regards, Imran MS CRM Certified Professional http://microsoftcrm3.blogspot.com Chat with me on MSN / Gmail / Skype : ID Is :.. mscrmexpert@gmail.com "sailaja.crm@gmail.com" wrote: > Hi, > Is there any process (Code) to generate .csv files to all entities in > MSCRM at a ...

Macro
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: intel Hi, I'm thinking of buying Mac: Office 2008, but before I do I want to check that I will be able to download Scritpsmart collection of templates without any glitches: <http://www.bbc.co.uk/writersroom/scriptsmart/faq.shtml> Does anyone know if I can do this? Regards, SP. In article <ee98ff5.-1@webcrossing.caR9absDaxw>, StregaItalia@officeformac.com wrote: > Version: 2008 > Operating System: Mac OS X 10.4 (Tiger) > Processor: intel > > Hi, > > I'm thinking of buying Mac: Of...

encoding wmv file
hello I have a sample application developed in MFC dialog based project using directx sdk 9. the sample captures video from a webcam and saves it to a wmv file now i have to put that video into streaming server. i beleive that i will have to encode the wmv file using some codecs to put it into streaming server. i want to do the capturing and encoding simultaneously. below is a portion of my code to capture video // capture video pBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, // Pin category &MEDIATYPE_Video, // Media type p...

Attached Toolbars Macros
Excel 2003 I have a custom tool bar, this tool bar has several items, each item is pointing to a VBA code. This tool bar is attached to the worksheet. I've copied this spreadsheet to several computers. After I copied the spreadsheet I decided to rename the spreadsheet, after I renamed the spreadsheet the Toolbar Item's macros were still pointing to the old name, I reasigned each tool bar item to the current spreadsheet, saved the spreadsheet and everything was working on my computer, but when I re-copied the new spreadsheet to other computers and I clicked on the Toolbar Item...

Help with macro/and or formula?
Perhaps this is a silly question, but i just can't figure out how t format this worksheet. The problem is that a lot of the cells hav numbers in them with negative signs in the back instead of in the fron (ie. 23-) and i was wondering if anyone knew of a macro/formula i coul use to quickly fix this problem for all the cells. I would b extremely grateful. Thanks -- brefed1 ----------------------------------------------------------------------- brefed15's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3557 View this thread: http://www.excelforum.com/showthre...

How to Use One PST file on Two Computers?
Hello: I have a desktop machine with a pst file in my Outlook 2003. I would like to copy this pst file to my laptop. How do I synchronize the same file on 2 machines so I won't get duplicate e-mails? I use one premium Yahoo e-mail account and several free Yahoo accounts with YahooPOPs.. Thanks in advance, Spudy Hi Spudy, it is not possible by default to share PST files. A list of a list of third-party synctools are also on this site: http://www.slipstick.com/outlook/sync.htm On the Microsoft Office Marketplace site is a list of third-party messaging tools: http://office.microsoft.com...

File location?
Where are the aspx files stored? http://site/subsite/list/defautl.aspx where would i find that? the reason i ask is when i go to export there are a couple of files that im told access denied. not sure why since im the admin on all levels. Thanks Justin Well, that really depends... mostly your stuff is stored in SQL, which means that its really data in a table cell. However, depending on whether a page has been customized or not it could be pointing to definition files that are stored on the Web Front End servers, and you really want to leave those alone. Furthermore, th...

Run macro automatically.
How do I make a macro run automatically when a worksheet it is attached to is loaded? right click on the sheet tab>view code>left window worksheet>right window activate -- Don Guillett SalesAid Software donaldb@281.com "Excel macro" <Excel macro@discussions.microsoft.com> wrote in message news:DD7AF1E3-9263-4523-AC49-A43ABA1AB9D0@microsoft.com... > How do I make a macro run automatically when a worksheet it is attached to is > loaded? I am unable to find "activate " when I right click on worksheet. ( i assume that you are referring to the windo...

save box greyed out
in ooutlook 2000 I can open office documents directly from outlook by just clicking on them no prompt it just opens (ie:word) also when opening non office attachments i get this box with save open grayed out example on webpage. http://www.planetarrakis.net/images/image1.jpg how can i fix it so i can either save from here or just open my paint program with out the prompt box? .. ...

Protected sheets and running macros
i have a sheet with a macro ran by a normal button at the top. Howeve when i protect the worksheet where ever i click on the sheet the macr executes. Can any one offer any advice on how to stop this? Thanks Robert -- Message posted from http://www.ExcelForum.com hi, i am not able to reproduce the problem, hence i may not be able t provide a panacea for that issue. here is what i suggest. i have a sheet that has a macro that is run when a control toolbo button (that is, not a form button) is clicked. this sheet is protected based on the user logged in. what i have don is to protect t...

Importing a pst file in Outlook XP
My computer's configuration changed and I had to delete some hard disk partitions. After doing that, when I open Outlook it pops up a window saying "Unable to open your default e-mail folders. The file F:\{...}\outlook .pst could not be opened". Then I press OK and then a new pop-up says "Would you like to open your default File System folder instead?" If I press Yes, Outlook opens without (of course) the outlook.pst file. Also, I can't import my pst file neither I can Create a new one. If I press No, Outlook closes. Does anyone know how to open my pst fil...

File In Use
I am trying to open an excel program that is shared on a network drive. When I go to open it the following message box pops up.... File In Use name.xls is locked for editing by 'user name'. open by 'read only' or click 'notify' to open read-only and receive notification when the document is no longer in use. The user name that it is saying is me and I don't have the file open. Does anyone know why it is saying this or how to fix it? I guess it thinks I have the file open, maybe it didn't close right but I can't figure it out. Thanks Dave ma...

Saving in 2003 Excel
I am currently taking Excel 2002 in college. The software I have loaded is 2003 but my Professor is running 2002. Can someone tell me how ot save in 2003 so the Professor can read in 2002? Hi Terry! Just save normally. You version challenged Professor will be able to open it. -- Regards Norman Harker MVP (Excel) Sydney, Australia njharker@optusnet.com.au Excel and Word Function Lists (Classifications, Syntax and Arguments) available free to good homes. Same file format, no problems.. -- Regards, Peo Sjoblom "Terry" <our.email@fuse.net> wrote in message news:384d...

Macro Freezes Reading Pane
I have a macro that Sends/Receives Tasks from Project Server into Outlook Tasks. Everything is working fine, except one weird thing that happens. I have the Timer set on the macro and it starts as soon as Outlook starts. The macro gets the tasks from ProjectServer every hour. As soon as the macro starts running the Reading pane freezes in the Inbox. If i stop the macro then Reading pane is back to normal. Can anyone please tell me if there is something I can do in VBA to fix this annoying issue. Thanks a lot ...

Macro to remove rows?
Hi, I receive thousands of rows of data from an extract that comes from a database. The data extract automatically generates page headers that need to be removed, and I would love to automate this process. The headers do have a pattern to them, but I'm not clever enough to figure out a good way to use that to write a macro. The first row of the header starts with hyphens ------------------------------- Then there's a variable number of rows of header data to delete followed by another row of hyphens ------------------------------- Then 2 additional rows that must be deleted. The nu...

transfer investment account from one .mny file to another
Hi, I am using Microsoft Money Plus Home & Business version 17.0.150.1415. I use it to keep track of my personal finances in one .mny file, and I use it to keep track of business finances in another .mny file. In the .mny file for my business, I just created an Investment account and added about ten stocks to it. I should have created this in my personal .mny file. Can anyone tell me if there is a way I can move this one investment account (and the stocks included in it) from my business .mny file to my personal ..mny file? Thanks in advance, Paul -- Paul Kraemer In m...