Code saves file in wrong location

PintaPinta

New Member
Joined
Jun 13, 2019
Messages
7
I am new to macros and VBA. I built a macro by scraping a few bits of code I found online so this may look a bit messy but it is very close to working for me.

My macro basically takes a column in excel and pastes it into a new workbook in order to save it as a .msg file (opens in notepad as the text that is in the columns. This file it produces is then used in a handheld inkjet printer.

I have it almost working but the folder that it saves this file to needs to be able to be changed regularly by the user. The way i tried to do this is by having the path refer to a cell in the spreadsheet that has the path necessary. My issue is in the SaveAs part of the macro.

I am trying to save to the following folder
P:\users\R&DGROUP\Projects\704 CalTrain Thermal and Acoustical Insulation\4. Drawings\Wagon AB\Printer Programs\AB3\MSGGROUP

With the file name: AB3-19

But instead it saves to
P:\users\R&DGROUP\Projects\704 CalTrain Thermal and Acoustical Insulation\4. Drawings\Wagon AB\Printer Programs\AB3

With the Filename: MSGGROUPAB3-19.msg

In the code below, in green has a few more details about the file path.


Sub Macro12()
'
' Macro3 Macro
'


'
Range("O1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=RC[-9]"
Range("O1").Select
Selection.AutoFill Destination:=Range("O1:O191"), Type:=xlFillDefault
Range("O1:O191").Select
Selection.SpecialCells(xlCellTypeFormulas, 1).Select
Selection.Delete Shift:=xlUp


'
' Macro4 Macro
'


'
Columns("O:O").Select
Selection.SpecialCells(xlCellTypeFormulas, 23).Select
Selection.Copy




'
' SaveAs Macro
'


'
Dim Filename1 As String
Dim Folder1 As String


Filename1 = Range("L2").Text
Folder1 = Range("L3").Text ' The folder1 cell looks like this "\Wagon AB\Printer Programs\AB3\MSGGROUP" Where the AB and AB3 are variables that are set by the person
' because depending on the work the output folder will change so one time it will go by the path about or else it could go on a path like this "\Wagon E\Printer Programs\E3\MSGGROUP". The cell looks like this =""&N5&" "&N6&""&"Printer Programs"&""&N2&""&"MSGGROUP"



Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ChDir "P:\users\R&DGROUP\Projects\704 CalTrain Thermal and Acoustical Insulation\4. Drawings"
ActiveWorkbook.SaveAs Filename:="P:\users\R&DGROUP\Projects\704 CalTrain Thermal and Acoustical Insulation\4. Drawings" & Folder1 & Filename1 & ".msg" _
_
, FileFormat:=xlText, CreateBackup:=False
ActiveWindow.Close




End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I figured it out. Maybe not elegantly but I added a "" to the end of the folder path in my excel cell and that gets me there. Not sure why that's needed but it works and I'm still learning.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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