For some reason, my macro doesn't save my file as an xlxs and instead just shows up as "File" which is unopenable. I've done some troubleshooting so hopefully someone can help me figure it out. The code in question is below.
Sub reverseandsave()
Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Rows("3:3").Select
Selection.Cut
Rows("1:1").Select
ActiveSheet.Paste
Rows("3:3").Select
Selection.Delete Shift:=xlUp
'
Range("A3:B3").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$4"
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
'
ThisFile = Range("A1").Value
ActiveWorkbook.SaveAs Filename:=ThisFile, FileFormat:=51
End Sub
I tried troubleshooting by removing the three pieces of individual code above, but it all gave my the unreadable file.
The two main things I want are: Reverse order of A1 and A2 in file, and then save as .xlxs using value in A1.
OLD A1: typically something like "AB1-41242-R2402"
OLD A2: typically something like "Company Car, Ltd."
NEW A1: typically something like "Company Car, Ltd."
NEW A2: typically something like "AB1-41242-R2402"
Both A1 and A2 are saved as text. Sometimes when I run the code and set it to take the value of A2 instead of A1, it appears correctly. I'm not sure if it's because the NEW A2 more closely resembles a value.
If I run this code by itself, it saves properly as .xlxs (BEFORE THE REVERSAL OF A1 and A2). The size of the unopenable file is the same as the .xlxs file when it works, so I'm assuming something with the converting is going wrong.
ThisFile = Range("A1").Value
ActiveWorkbook.SaveAs Filename:=ThisFile, FileFormat:=51
If anyone can help, that would be great. Thanks in advance.
Edit: The second part of the code where I copy and paste is for the =now() function. I paste the values so it saves as text and doesn't change every time.
Bookmarks