Results 1 to 7 of 7

Thread: display replace confirmation message for word file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2012
    Posts
    28

    display replace confirmation message for word file

    hi,

    i want to pop up replace dialogue box for word file if file already exists at specified location.

    thanks,
    kk

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: display replace confirmation message for word file

    are you using FSO? If so, use the fileexists method.

    Can we see some code?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2012
    Posts
    28

    Re: display replace confirmation message for word file

    FSO?

    i am new to VB6. have used so many years ago...

    is there any save as method available for word file like excel file?

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: display replace confirmation message for word file

    There are MANY ways to 'save as', yes....suggest you MSDN the FileSystemObject (FSO), or better yet, google it, and include the word "fileexists". Write some code so I'll know what you are attempting. There are other options, and FSO may not be the best....but I tend to use it a lot when working with files and directories.

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: display replace confirmation message for word file

    Actually instead of the FSO you should use the built in DIR$() method.

    Code:
    If Dir$(Filename)<>"" then

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: display replace confirmation message for word file

    Roger, Data, You are right. But then if the file exists he'll have to decide to overwrite or cancel.

    Krunel....if you want a saveas for excel (or word), the format is like this:

    oActiveBook.SaveAs FileName:=App.Path + "\myExcelFile.xlsx"

    but you will have to add Microsoft's Excel Library to your project, and set a few variables (like oActiveBook in the above line, amongst others)....google 'visual basic 6' excel, and you will find MANY examples.

  7. #7
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: display replace confirmation message for word file

    here is a sample i did not include you saving code becaus i do not know how you want to save

    Code:
    Private Sub Command1_Click()
    Dim FileName As String
    
    On Error GoTo ErrHandler
    
      FileName = "C:\ScreenShot.bmp" 'Write file path here
        If Dir(FileName) <> "" Then
          If MsgBox("File '" & FileName & "' already exits, would you like to replace the file?", vbExclamation + vbYesNo, "Replace File?") = vbYes Then
            Kill FileName
            Do Until Dir(FileName) = ""  'Do Until File does not exist
              DoEvents
            Loop
            Debug.Print "Deleted File... Now Replacing"
            'Here would be the saving function (save file)
            Debug.Print "File Saved!"
          End If
        Else
          Debug.Print "Does not Exist"
        End If
        Exit Sub
    ErrHandler:
      MsgBox Err.Description
    End Sub

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width