If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > VBA Code For Macro?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-09-04, 16:04
scobad scobad is offline
Registered User
 
Join Date: Jun 2004
Posts: 23
Exclamation VBA Code For Macro?

I am Tring to HAVE a MACRO that does the following:

When the Button is Selected:
1. The File Prompts USER to save in a Directory of their CHOICE.
2 Automatically Names the SAVED File in the following Scheme>
SES_TimeCard_###

The ### is the value of cell C2

Here is My Code:

ChDir "C:\"
ActiveWorkbook.SaveAs Filename:="C:\SES_Time_061204.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
Application.Dialogs(xlDialogSendMail).Show
Range("A1").Select
End Sub

Thank you !!!
Reply With Quote
  #2 (permalink)  
Old 06-10-04, 08:07
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
Here is a soloution to your problem

Code:
Private Sub cmdSave_Click()
    Dim MyFile As String
    Dim SaveFile As String
    Dim MyCheck As String
    'get the filename
    MyFile = "SES_TimeCard_" & Range("C2").Value
    'get the save location and name
    SaveFile = Application.GetSaveAsFilename(MyFile, , , SaveLocation)
    'strip off the directory path to check filename
    MyCheck = Right(SaveFile, Len(SaveFile) - InStrRev(SaveFile, "\"))
    MyCheck = Left(MyCheck, InStrRev(MyCheck, ".") - 1)
    If MyCheck <> MyFile Then
        'if filename changed put back to original filename
        SaveFile = Left(SaveFile, InStrRev(SaveFile, "\")) & MyFile
        MsgBox "Saving file as ..." & Chr(10) & SaveFile
    End If
    'save the file
    ActiveWorkbook.SaveAs SaveFile, xlNormal
    Application.Dialogs(xlDialogSendMail).Show
End Sub
HTH

David
Reply With Quote
  #3 (permalink)  
Old 06-10-04, 11:08
scobad scobad is offline
Registered User
 
Join Date: Jun 2004
Posts: 23
Exclamation Just a Couple of BUGS

1. When you hit the button - The save box pops up. When you hit save you get:

Run-time Error 1004:
Microsoft Excel cannot access the file c:\documents and settings\sb\desktop\SES_TimeCard_06/12/04

Several Reasons Why
- File or path does NOT exist
- used by another program
Close and tray again.

I think It is BECAUSE cell C2 is a DATE
Format (06/12/04) I need to convert to string 06_12_04

Also, When I select Debug - This line is YELLOW:
ActiveWorkbook.SaveAs SaveFile, xlNormal
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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