Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Changing a File SaveAs parameter to a new variable

Posted on 2014-10-24
4
Medium Priority
?
88 Views
Last Modified: 2014-10-28
I use the code below to save a file.  What I need is the filename to change.  I have a variable name: SalesOrderNum, and I would like to save this in a format: [SalesOrderNum]_lines.xlsx

How would I change the myFileNameO to save file correctly?  Then later in the procedure I need to open it back up.  How would in use the same myFileNameO or variable [SalesOrderNum] to reopen the file when needed?  Please advise and thanks.

myDirECTorY = "C:\temp\"        'Wherever you want
myFileNameO = myDirECTorY & Format(Now(), "yyyymmdd_hhmm") & " report" & ".xlsx"    

Workbooks.Add
ActiveSheet.Paste
ActiveWorkbook.SaveAs Filename:=myFileNameO, FileFormat:= _
      xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close

Open in new window

0
Comment
Question by:RWayneH
  • 3
4 Comments
 
LVL 7

Accepted Solution

by:
Steve earned 2000 total points
ID: 40402689
This will save it but to reopen it you will have to get the "SalesOrderNum" the file was saved with to open it.

myDirECTorY = "C:\temp\"        'Wherever you want
myFileNameO = myDirECTorY & SalesOrderNum & "_Lines.xlsx"

Workbooks.Add
ActiveSheet.Paste
ActiveWorkbook.SaveAs FileName:=myFileNameO, FileFormat:= _
      xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close

'***********************************************************

PathName = myDirECTorY
FileName = SalesOrderNum & "_Lines.xlsx"

Workbooks.Open FileName:=PathName & FileName

Open in new window

0
 

Author Comment

by:RWayneH
ID: 40402723
Ok, thanks for the save part, however later in the procedure [SalesOrderNum] should be the same as it is when it was saved.  Perhaps I should just leave it open?   No...

How would it look to open it, assuming that [SalesOrderNum] value is the same?
0
 

Author Comment

by:RWayneH
ID: 40402913
I made a mistake in the save part, it needs to be saved as an .xml  Will it matter if I just change the .xlsx in myFileNameO to .xml?  and I will definitely need to reopen the .xml   I will need to save it as a variable and use that later in the procedure.  The variable needs to be the full file path as text.

Sample on a given time would be: C:\_SAP\Extracts\SalesOrd\200304647_Lines.XML      the 200304647 would be whatever [SalesOrderNum] is.

So the next time it could be: C:\_SAP\Extracts\SalesOrd\200304648_Lines.XML  that [SalesOrderNum] is dynamic.  Hope this makes sense
0
 

Author Closing Comment

by:RWayneH
ID: 40409797
Thanks for the help!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question