Save .xlsm using PC name if file does not exist

Spectrum0311

New Member
Joined
Jan 2, 2010
Messages
2
Hello All,

This will be my 1st posting and I would greatly appreciate some advise on the best way to handle what I am attempting to accomplish. Basically, I would like to open an excel workbook file (.xlsm) and rename the file using the PC name ("Book1" & PC_Name).

Obviously, I do not want the file to be overwritten if it already exists. In which case, if the file name already exists, then I would just need the file to open.


  • Find PC Name
  • Check for existing file using the PC Name and open if already exists
  • Save the current workbook using the PC Name ("Book1" & PC_Name) if no file match found.
I should probably mention that the path will be the static and will not change. Example: (c:\\home\excel_files\Book1" & PC_Name).

Thank you for your greatly appreciated help.


-- removed inline image ---
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You will need to make some minor changes but this should give you the basic structure.

Code:
Sub FileExists1()
Dim FSO As Object
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FileExists("C:\" & Environ("COMPUTERNAME") & ".XLSM") Then
    Workbooks.Open ("C:\" & Environ("COMPUTERNAME") & ".XLSM")
Else
    ActiveWorkbook.SaveAs ("C:\" & Environ("COMPUTERNAME") & ".XLSM")
End If
End Sub

Cheers

Dan
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top