Save File VBA code works perfectly....except.....

jmk15315

Board Regular
Joined
Nov 7, 2021
Messages
59
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
So with the help from others here, I have landed on the following code. It works perfectly, with the exception that it does not allow the user to choose the folder in which to save the file to. I thought I could figure it out, but everything I have tried, has failed. Hoping someone can point me in the correct direction.


Private Sub CommandButton2000_Click()

If Sheet2.Range("G20").Value = "NOT NEW" Then
GoTo 900
Else
End If

Dim FileExtStr As String
Dim FileFormatNum As Long
Dim TempFilePath As String

TempFilePath = ThisWorkbook.Path
Dim NewFileName As String
FileExtStr = ".xlsm": FileFormatNum = 5

Sheet2.Visible = True
NewFileName = Sheets("DATA FILE").Range("G11").Value & " - " & Sheets("DATA FILE").Range("G12").Value & " - " & Sheets("DATA FILE").Range("G22").Value
Sheet2.Visible = False

ActiveWorkbook.SaveAs TempFilePath & "\" & NewFileName & FileExtStr

Application.ScreenUpdating = True

Application.EnableEvents = True

MsgBox "Success - The file has been saved to: '" & TempFilePath & NewFileName & "'", vbInformation

Sheet2.Visible = True
Sheet2.Select
Range("G20").Select
ActiveCell.FormulaR1C1 = "NOT NEW"
Sheet2.Visible = False

900
With MeetingData
MeetingData.Height = 423
MeetingData.Width = 893
End With
Load MeetingData
MeetingData.MultiPage1.Value = 1
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Perhaps replace this:

VBA Code:
TempFilePath = ThisWorkbook.Path

with this:
VBA Code:
       'File dialog folder select
       With Application.FileDialog(msoFileDialogFolderPicker)
           .InitialFileName = ThisWorkbook.Path
           .Filters.Clear
           .AllowMultiSelect = False
       
           'Use the Show method to display the FolderPicker dialog box and return the user's action.
           If .Show = -1 Then    'User picked one or more folder
               TempFilePath = .SelectedItems.Count
           Else    'The user pressed Cancel.
               MsgBox "User Cancel"
               Exit Sub
           End If
       End With

(Not tested)


(Tip: For future posts , you should try to use code tags like I did above when posting your code. It makes it easier to read.)

 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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