Results 1 to 11 of 11
  1. #1
    Join Date
    Jul 2006
    Posts
    157

    Unanswered: Open Excel when user press OK button

    Hi: This is the message box which shows that the file is save in the my document folder with the file name. Can any one please tell me how to i create another message box with OK Cancel button and with the message "Do you want to open that excel file" If user press Ok it open the excel with that file and if user press cancel it will be stay in the current form.

    MsgBox "Your document is in My Documents with the name 'Accounts-Distribution " & Format$(Date, "yyyymmdd") & "-" &

    Format$(Time, "hhmmss") & "-" & maxbatchID & ".xls'"

    Thanks.

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    I think if you are going to make the time (down to the second) part of your file name, you are going to have to save that file name in a variable.

    Code:
    Dim intReply as Integer
    ...
    strFileName='Accounts-Distribution " & Format$(Date, "yyyymmdd") & "-" & 
    Format$(Time, "hhmmss") & "-" & maxbatchID & ".xls'"
    'save file as strFileName
    ...
    intReply = MsgBox("Your document is in My Documents with the name " & strFileName". & vbCrLF & " Do you want to open it now?", vbOkCancel)
    If intReply=vbOK then
       'open the file
    Elseif intReply=vbCancel then
       'exit the function
    End if
    Inspiration Through Fermentation

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    MsgBox(prompt[, buttons] [, title] [, helpfile, context])

    Write your prompt then add a comma - select your mesgbox type.

    EDIT: Did you know that in the VB Editor - if you put the mouse cursor into a word, such as MsgBox and hit F1 - the helpfile will open on that function! I suggest you give it a try and a read!
    George
    Home | Blog

  4. #4
    Join Date
    Jul 2006
    Posts
    157
    Hi: Thanks for your reply, it gives syntax error on this line
    Expected: list separator or )

    intReply = MsgBox("Your document is in My Documents with the name " & strFileName". & vbCrLF & " Do you want to open it

    now?", vbOkCancel)

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    copy this in instead:

    MsgBox "Your document is in My Documents with the name " & strFileName". & vbCrLF & " Do you want to open it now?", vbOkCancel

    Note that the full thing should be on line.
    George
    Home | Blog

  6. #6
    Join Date
    Jul 2006
    Posts
    157
    same expected end of statement
    ". & vbCrLF & "

  7. #7
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    There's a missing " and a missing & in my code. I'll leave it to you to find it.
    Inspiration Through Fermentation

  8. #8
    Join Date
    Jul 2006
    Posts
    157
    This is the complete line which i copied
    MsgBox "Your document is in My Documents with the name " & strFileName". & vbCrLF & " Do you want to open it now?", vbOkCancel

  9. #9
    Join Date
    Jul 2006
    Posts
    157
    Ok i try it.

  10. #10
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    my apologies, wasn't looking at that bit. the culprit is highlighted below:

    MsgBox "Your document is in My Documents with the name " & strFileName & ". " & vbCrLF & " Do you want to open it now?", vbOkCancel
    George
    Home | Blog

  11. #11
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Remember: All text must be surrounded by quotes.
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •