Solved

Changing a File SaveAs parameter to a new variable

Posted on 2014-10-24
4
72 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now