File Name

Aaron

Board Regular
Joined
Feb 20, 2002
Messages
237
If I have a file that over forty people will be using, how can I get my macros to run if the user decides to change the name of the file? If you want to see my code let me know, and I will post it. Any help would be greatly appreciated.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Unless your code searches for that particular file (i.e. the workbook whose name may be changed) there shouldn't be a problem running the macros. I think you're going to have to show some of your code here.

Perhaps, just the code that is meant to start the code running.
 
Upvote 0
Thank you for the quick response. My code is really basic, and I apologize for that. I am merely learning the great capabilities of VBA.

Sub CreateExtract()
Workbooks.Add
Windows("MFGIndirectModeltest.xls").Activate
Sheets("FORECAST").Select
Cells.Select
Selection.Copy
ActiveWindow.ActivatePrevious
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Columns("A:A").EntireColumn.AutoFit
Columns("B:D").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("A1:A2000").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
Range("A1").Select
ActiveWorkbook.SaveAs _
FileName:="D:Personal" & Worksheets("Sheet1").Range("A1").Value & "I.xls", _
FileFormat:=xlNormal, _
Password:="mfgie", _
WriteResPassword:=""
ActiveWindow.Close SaveChanges:=True
Windows("MFGIndirectModeltest.xls").Activate
Range("A30").Select
Sheets("Instructions").Select
End Sub

I apologize in advance for the code being so long, but I am just scratching the surface of the files
 
Upvote 0
That's cool, everyone has to start from somewhere, this part of the code is your problem:

<pre>
Workbooks.Add
Windows("MFGIndirectModeltest.xls").Activate </pre>

I would change this to something like:

<pre>
'Declare Variable
Dim sThisWorkbook As String

'Intialise variable
sThisWorkbook = ThisWorkbook.Name

Workbooks.Add
Windows(sThisWorkbook).Activate
</pre>

Then it shouldn't matter what the workbook is called, it's always going to use the workbook that the code is situatuated in.

HTH
 
Upvote 0
Mark,

Thanks for your help, that works fabulously. My next question in the same code above is, the Close Method: I have SaveChanges as True, how can I get the code to overwrite the file. Instead of having a dialogue Box pop up and ask me if I want to overwrite the existing file, just have it automatically overwrite the existing file. Again many thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,031
Members
448,940
Latest member
mdusw

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