VBA Code Save When Switching Windows

jbeck08

New Member
Joined
May 9, 2019
Messages
1
Currently, we have a macro that stops and forces you to save the file when it switches between windows. We'd like it to be able to run all the way through without forcing this save option, any help on resolving this issue would be greatly appreciated. I've attached a portion of the VBA code and bolded the section that is forcing the issue.

Cells.Select
Range("M22").Activate
Cells.EntireColumn.AutoFit
Selection.ColumnWidth = 9.78
Cells.EntireColumn.AutoFit
Application.CutCopyMode = False

ChDir "J:\Macro Save As Files"
ActiveWorkbook.SaveAs Filename:="J:\Macro Save As Files\Taxability Test.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Range("M22").Select
Windows("monthlysales.xls").Activate
Range("C3").Select
ActiveCell.FormulaR1C1 = "ST"
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Is the workbook you're in when you try to run this the taxability test? Because if so it may be easier to just do a save instead of a save as. Because my guess is it is stopping because it's now trying to replace a file
 
Last edited:
Upvote 0
If it isn't the same workbook you could try putting this in there

Code:
Application.DisplayAlerts = False

Code:
[COLOR=#333333]Cells.Select[/COLOR]
[COLOR=#333333]Range("M22").Activate[/COLOR]
[COLOR=#333333]Cells.EntireColumn.AutoFit[/COLOR]
[COLOR=#333333]Selection.ColumnWidth = 9.78[/COLOR]
[COLOR=#333333]Cells.EntireColumn.AutoFit[/COLOR]
[COLOR=#333333]Application.CutCopyMode = False
Application.DisplayAlerts = False
[/COLOR]
[B][COLOR=#000000]ChDir "J:\Macro Save As Files"[/COLOR]
[B][COLOR=#000000]ActiveWorkbook.SaveAs Filename:="J:\Macro Save As Files\Taxability Test.xlsx" _[/COLOR]
[B][COLOR=#000000], FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False[/COLOR]
Range("M22").Select
Windows("monthlysales.xls").Activate
Range("C3").Select
ActiveCell.FormulaR1C1 = "ST"[/B][/B][/B]
 
Upvote 0

Forum statistics

Threads
1,215,828
Messages
6,127,126
Members
449,361
Latest member
VBquery757

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