Consulting

Results 1 to 8 of 8

Thread: Open With

  1. #1
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    266
    Location

    Open With

    Is it possible to:

    1. open a document using a dialog box
    2. save the document with the same name but use .xml extension
    3. open the new .xml document in wordpad
    4. do a find and replace
    5. save

    this is what I have so far:

    Sub PickAndProcess()
      Dim intChoice As Integer
      Dim strPath As String
      Dim objWord As Object
      Set objWord = CreateObject("Word.Application")
      objWord.Visible = True
      Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
      intChoice = Application.FileDialog(msoFileDialogOpen).Show
      If intChoice <> 0 Then
      strPath = Application.FileDialog( _
      msoFileDialogOpen).SelectedItems(1)
         
      End If
      
      Dim doc As Document
      Set doc = Documents.Open(strPath)
      
      With doc
        Dim strDocName As String
        Dim intPos As Integer
        strDocName = ActiveDocument.Name
        intPos = InStrRev(strDocName, ".")
        strDocName = Left(strDocName, intPos - 1)
        strDocName = strDocName & ".xml"
        ActiveDocument.SaveAs2 FileName:=strDocName, _
        FileFormat:=wdFormatXML
       End With
    ActiveDocument.Close
    'oDoc = strDocName????
    'With oDoc
        'Open with notepad
        'find text
        'replace text
        'save
        'close
    'End With
    'open xml document
    'save as .docx
    
    End Sub


  2. #2
    Neither Wordpad nor Notepad are programmable using VBA. What are you trying to do?
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    266
    Location
    Thanks Graham.

  4. #4
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    266
    Location
    I realize my end game is not achievable. But, is it possible to do the "open with" part?

  5. #5
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    266
    Location
    Ok I kind of figured out how to open but I can’t get thevariable “StrDocName” to be recognized. It is usually a direct documentaddress.

    Dim vPID As Variant
    vPID = Shell("notepad.exe""strDocName",vbNormalFocus)

    Is it possible?


  6. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    Maybe:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oFile
    Dim strFileName As String
      strFileName = "D:\Book1.xlsx"
      oFile = Shell("C:\WINDOWS\notepad.exe " & strFileName, 1)
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  7. #7
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    266
    Location
    adding "C:\WINDOWS" in front of "notepad.exe" did the trick.

  8. #8
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    266
    Location
    Thanks for your help Graham and Greg!

Posting Permissions

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