Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
matpoh
 
Posts: n/a
Default Forcing a macro to pause for filename


Just wondering how I would get a macro to pause to allow me to change a
filename and then when I hit enter, it continues.

I use it to export excel worksheets to our webserver and it works now,
but overwrites the file name everytime. I want to change the filename
before saving.

Any help appreciated.


--
matpoh
------------------------------------------------------------------------
matpoh's Profile: http://www.excelforum.com/member.php...o&userid=27024
View this thread: http://www.excelforum.com/showthread...hreadid=466247

  #2   Report Post  
Dave O
 
Posts: n/a
Default

This line of code opens a Save As dialog box, allows you to click to
your filepath, and specify a file name.

Application.Dialogs(xlDialogSaveAs).Show

  #3   Report Post  
matpoh
 
Posts: n/a
Default


Is there a way to have the macro keep the same directory, but allow for
file name change?


--
matpoh
------------------------------------------------------------------------
matpoh's Profile: http://www.excelforum.com/member.php...o&userid=27024
View this thread: http://www.excelforum.com/showthread...hreadid=466247

  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

You could get a filename with something like this (ignoring the folder):

Option Explicit
Sub testme()
Dim myFileName As Variant
Dim iCtr As Long
Dim SlashChar As String
Dim myFolder As String
Dim resp As Long

myFolder = "c:\my documents\excel"
If Right(myFolder, 1) < "\" Then
myFolder = myFolder & "\"
End If

myFileName = Application.GetSaveAsFilename _
(filefilter:="Excel Files, *.xls")

If myFileName = False Then
'what happens if you cancel?
Else
For iCtr = Len(myFileName) To 1 Step -1
SlashChar = Mid(myFileName, iCtr, 1)
If SlashChar = "\" Then
'found it
myFileName = Mid(myFileName, iCtr + 1)
Exit For
End If
Next iCtr

myFileName = myFolder & myFileName

resp = vbYes
If Dir(myFileName) < "" Then
resp = MsgBox(prompt:="Wanna overwrite it?", Buttons:=vbYesNo)
End If

If resp = vbYes Then
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=myFileName, _
FileFormat:=xlWorkbookNormal
Application.DisplayAlerts = True
Else
'what should happen if you don't want to overwrite it?
End If
End If

End Sub

But if you know you want to write to a unique filename, maybe you could just
append the date and time to the filename:

if lcase(right(myfilename,4)) = ".xls" then
myfilename = left(myfilename,len(myfilename)-4)
end if

myfilename = myfilename & "_" & format(now,"yyyymmdd_hhmmss") & ".xls"

Then unless you do something very, very quickly <vbg, you'll have a unique
name.




matpoh wrote:

Is there a way to have the macro keep the same directory, but allow for
file name change?

--
matpoh
------------------------------------------------------------------------
matpoh's Profile: http://www.excelforum.com/member.php...o&userid=27024
View this thread: http://www.excelforum.com/showthread...hreadid=466247


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to pause for user input in dialog box kayabob Excel Discussion (Misc queries) 1 June 22nd 05 07:49 PM
How do I pause a macro to select specific cells lee Excel Worksheet Functions 1 April 2nd 05 02:11 PM
Macro to move to specified cells, pause for input at each? Pete in Montrose Excel Discussion (Misc queries) 1 March 5th 05 06:18 PM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM


All times are GMT +1. The time now is 11:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"