using inputbox content in filesaveas routine

colinharwood

Active Member
Joined
Jul 27, 2002
Messages
437
Office Version
  1. 365
Platform
  1. Windows
Hi I am trying to take the value from an inputbox to use as the directory path in a filesaveas routine, but cannot figure out the correct format using the following code

Sub Path_Exists()
Dim Path As String
Dim Folder As String
Dim Answer As VbMsgBoxResult
Dim Response As String
'Update the path to a valid path on your PC
Path = "D:\Tonbridge MES"
Folder = Dir(Path, vbDirectory)

If Folder = vbNullString Then
Answer = MsgBox("Path D:\Tonbridge MES does not exist. Would you like to create it?", vbYesNo, "Create Path?")
Select Case Answer
Case vbYes
VBA.FileSystem.MkDir (Path)
Case Else
Response = InputBox("Please enter the location where you would like the file saved to.")
ActiveWorkbook.SaveAs FileName:="Response" \ "Email list", FileFormat:=xlCSV

End Select

End If
End Sub

It works up until the Case else statement. ANy help much appreciated
Thanks
Colin
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Yoiu have a few things backwards. Only literal text is enclosed in double-quotes, variables are not. And you join the various pieces with an ampersand (&).
So this line:
VBA Code:
ActiveWorkbook.SaveAs FileName:="Response" \ "Email list", FileFormat:=xlCSV
would need to look something like this:
VBA Code:
ActiveWorkbook.SaveAs FileName:=Response & "\Email list.csv", FileFormat:=xlCSV
 
Upvote 0
Hi Joe4
Just tried your change, but it still fails at the Activeworkbook saveas line
 
Upvote 0
It brings up a standard file choosing dialog box. Run this to she it in action.

VBA Code:
Dim uiPath as Variant

uiPath = application.GetSaveAsFilename

If uiPath = False Then
    MsgBox "user canceled"
Else
    MsgBox "path chosen is " & uiPath
End If
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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