Macro ActiveWorkbook.SaveAs problem windows 10

Ricasilva13

New Member
Joined
May 31, 2019
Messages
1
Good morning,

I have a problem with a macro that runs in windows 7 but on windows 10 it runs with a small problem.

Macro:

Sub XXX()
'
' Macro1 Macro

'Sheet of the activeworkbook that you want save as separated workbook
Sheets("XXXXXXX").Copy

Dim Path As String
Dim filename As String
ActiveWorkbook.SaveAs filename:=Range("A2").Value & " - " & Range("D5").Value & ".xlsx", FileFormat:=xlOpenXMLWorkbook

Columns("A:H").Select
Columns("A:H").Copy
Columns("A:H").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

End Sub

So on windows 7 if i run the macro, it will open the sheet that im working on and save with the name on the cells A2 - D5.

But on windows 10 instead of saving with the name on the cells A2 - D5, we creates a folder with the name in A2 and then saves the file with the name on D5.


Best regars
Ricardo Silva
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Let's use the variables fpath and filename


Try this

Code:
Sub XXX()
'
' Macro1 Macro


'Sheet of the activeworkbook that you want save as separated workbook
    Sheets("XXXXXXX").Copy
    
    Dim fPath As String
    Dim filename As String


[COLOR=#0000ff]    fPath = ThisWorkbook.Path & "\"[/COLOR]
[COLOR=#0000ff]    filename = Range("A2").Value & " - " & Range("D5").Value & ".xlsx"[/COLOR]
    ActiveWorkbook.SaveAs filename:=[COLOR=#0000ff]fPath [/COLOR]& [COLOR=#0000ff]filename[/COLOR], FileFormat:=xlOpenXMLWorkbook
    
    Columns("A:H").Select
    Columns("A:H").Copy
    Columns("A:H").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,745
Messages
6,180,700
Members
452,994
Latest member
Janick

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