PDA

View Full Version : [SOLVED:] Open With



Kilroy
07-15-2019, 01:41 PM
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

gmayor
07-15-2019, 08:21 PM
Neither Wordpad nor Notepad are programmable using VBA. What are you trying to do?

Kilroy
07-16-2019, 03:26 AM
Thanks Graham.

Kilroy
07-16-2019, 04:57 AM
I realize my end game is not achievable. But, is it possible to do the "open with" part?

Kilroy
07-16-2019, 05:48 AM
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?

gmaxey
07-16-2019, 07:02 AM
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

Kilroy
07-16-2019, 07:50 AM
adding "C:\WINDOWS" in front of "notepad.exe" did the trick.

Kilroy
07-16-2019, 09:38 AM
Thanks for your help Graham and Greg!