Saving a copy of my workbook to a folder I just created on a button click

Jwalker1973

New Member
Joined
Feb 21, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hey all new registered user and I have an issue. I created some VBA code to check for a folder existence and create it if not. That part works great. Even got it to use one of my textbox values to so I could variablize the folder name. The problem is when it saves. It does not save to the folder and the filename is messed up.

Private Sub CommandButton1_Click

If Len(Dir("C:\Users\Jamie\Documents\Set Up Trend Data\ " & Sheet1.TextBox1.Value, vbDirectory )) = 0 Then
MkDir "C:\Users\Jamie\Documents\Set Up Trend Data\ " & Sheet1.TextBox1.Value
End If

That part works great.This issue is with the below.

Dim Filepath As String
Dim Filename As String
Filepath ="C:\Users\Jamie\Documents\Set Up Trend Data\ " & Sheet1.TextBox1.Value
Filename = Sheet1.TextBox2.Value
ActiveWorkbook.SaveCopyAs filename:= FileMaker & Filename & ".xls"

Any help would be appreciated. Sorry for the way post looksI am on my phone at work.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hey all new registered user and I have an issue. I created some VBA code to check for a folder existence and create it if not. That part works great. Even got it to use one of my textbox values to so I could variablize the folder name. The problem is when it saves. It does not save to the folder and the filename is messed up.

Private Sub CommandButton1_Click

If Len(Dir("C:\Users\Jamie\Documents\Set Up Trend Data\ " & Sheet1.TextBox1.Value, vbDirectory )) = 0 Then
MkDir "C:\Users\Jamie\Documents\Set Up Trend Data\ " & Sheet1.TextBox1.Value
End If

That part works great.This issue is with the below.

Dim Filepath As String
Dim Filename As String
Filepath ="C:\Users\Jamie\Documents\Set Up Trend Data\ " & Sheet1.TextBox1.Value
Filename = Sheet1.TextBox2.Value
ActiveWorkbook.SaveCopyAs filename:= FileMaker & Filename & ".xls"

Any help would be appreciated. Sorry for the way post looksI am on my phone at work.
Filepath on the last part sorry for the typo
 
Upvote 0
1) You appear to be missing a "\" between your filename and file path.
2) you have not included the filepath in the save line (not sure what the reference to filemaker is for in yoursave path so you may or maynot need to include it)

filepath in second part needs to be

VBA Code:
Filepath ="C:\Users\Jamie\Documents\Set Up Trend Data\ " & Sheet1.TextBox1.Value & "\"

saveline needs to be

VBA Code:
ActiveWorkbook.SaveCopyAs  Filepath & Filename & ".xls"
 
Upvote 0
Solution

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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