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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,217,047
Messages
6,134,265
Members
449,862
Latest member
Muhamad Irfandi

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