Solved

Changing a File SaveAs parameter to a new variable

Posted on 2014-10-24
4
80 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 7

Accepted Solution

by:
Steve earned 500 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

751 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