• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 44
  • Last Modified:

Adding a Variable to a File SaveAs

How would I define and name SalesOrderNum to use in a file saveas Sub
SalesOrderNum is in cell A2 of the active sheet.  Want that in the file save as name.

With a saving variable in the name.
''Saves as created [Sales Order]_Lines.xslx    need to chg? to .xml, needed?
''Save the downloaded file as a .xml and with the [SoLnNum]_Lines.xml
'myDirECTorY = "C:\_SAP\LynxFiles\"        'Wherever you want
'myFileNameO = myDirECTorY & [b]SalesOrderNum[/b] & "_Lines.xlsx"
'Workbooks.Add  'my need to remove this and make sure that Download.xml is active
'ActiveSheet.Paste 'May need to remove this too.
'ActiveWorkbook.SaveAs Filename:=myFileNameO, FileFormat:= _
'      xlOpenXMLWorkbook, CreateBackup:=False

Open in new window

1 Solution
Rodney EndrigaData AnalystCommented:
You can declare a variable as SalesOrderNum & use that to include it into the filename.

If your SalesOrderNum is always in Cell A2, then you can use this:
Dim SalesOrderNum as String
SalesOrderNum = cells(2,1).value
myFileNameO = myDirECTorY & SalesOrderNum & "_Lines.xlsx"

Open in new window

Martin LissOlder than dirtCommented:
Or just

myFileNameO = myDirECTorY & Range("A2").Value & "_Lines.xlsx"
RWayneHAuthor Commented:
Yup worked.  thanks. -R-
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now