Saving a workbook into the desktop

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Is it possible to code to save a file into a variable
directory?

ie: c:\documents and settings\variable computer
name\desktop

the code would search for the correct name and save the
Excel file to the desktop.
 
Sure - assuming you can come up with the computer name,
store it in a string variable (e.g. CompName) and then

ActiveWorkbook.SaveAs "C:\Documents and Settings\" _
& CompName & "\Desktop",...
 
I'm not sure how to search for the correct name, but this might get you started:

Option Explicit
Sub testme03()

Dim wsh As Object
Dim myPath As String

Set wsh = CreateObject("WScript.Shell")
myPath = wsh.SpecialFolders.Item("Desktop")

ActiveWorkbook.SaveAs Filename:=myPath & "\" & "whateveryouwant.xls", _
FileFormat:=xlWorkbookNormal

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top