Posts: 17
Threads: 6
Joined: Oct 2013
Hello,
I want integrate from vba to QM a "find and replace" macro recorded in ms word vba.
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 27.04.2014 by Sergiu
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "x1"
.Replacement.Text = "test"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub
I haven't found anything that could be helpful.
Thanks
Posts: 12,028
Threads: 139
Joined: Dec 2002
Macro
Macro2254
;/exe 1
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application a._getactive ;;connect to Word. On Vista/7, macro process must run as User. QM normally runs as Admin. The /exe 1 tells QM to run the macro in separate process, as User.
a.Run("Macro1")
Posts: 17
Threads: 6
Joined: Oct 2013
Is there any way to connect to ms word like excel and run my macro step by step;
for excel is :
ExcelSheet es1.Init
Excel.Application app=es1.ws.application
and then run macros with app.selection.find
Isn't there a way to run Word.Application a._getactive , and then simply translate my macro in QM
a.Selection.Find.ClearFormatting and so on ... ?
Posts: 12,028
Threads: 139
Joined: Dec 2002
This Word macro is easy to convert. Not tested.
Macro
Macro2254
;/exe 1
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application a._getactive ;;connect to Word. On Vista/7, macro process must run as User. QM normally runs as Admin. The /exe 1 tells QM to run the macro in separate process, as User.
;a.Run("Macro1")
Word.Find f=a.Selection.Find
f.ClearFormatting
f.Replacement.ClearFormatting
f.Text="x1"
f.Replacement.Text = "test"
f.Forward = TRUE
f.Wrap = wdFindContinue
f.Format = 0
;...
f.Execute
Posts: 133
Threads: 15
Joined: Jun 2014
Hi Gintaras,
Is it possible that I create a macro in which
I open a word document then calling macro2254 right after that?
Posts: 12,028
Threads: 139
Joined: Dec 2002
Which of the macros (macro and macro2254) is a QM macro and which is an Excel macro?
Posts: 133
Threads: 15
Joined: Jun 2014
I mean this macro:
Macro Macro2254 ?
;/exe 1
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application a._getactive ;;connect to Word. On Vista/7, macro process must run as User. QM normally runs as Admin. The /exe 1 tells QM to run the macro in separate process, as User.
a.Run("Macro1")
Posts: 12,028
Threads: 139
Joined: Dec 2002
Don't need 2 macros.
Macro
Macro2354
;run Word and open file
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application app._create
app.Visible = TRUE
Word.Documents docs=app.Documents
VARIANT d=_s.expandpath("$documents$\test.doc")
Word.Document doc=docs.Add(d)
;run a Word macro
app.Run("Macro1")
or can open in existing Word process
Macro
Macro2351
;/exe 1
;Use /exe 1 to run the macro in separate process, as User. This macro may not work without it.
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application app._getactive
Word.Documents docs=app.Documents
VARIANT d=_s.expandpath("$documents$\test.doc")
Word.Document doc=docs.Add(d)
act "Word"
doc.Activate
;run a Word macro
app.Run("Macro1")
Posts: 133
Threads: 15
Joined: Jun 2014
Hi Gintaras,
I found out that in Macro 2354, it did run the macro1 on the specified file but it open the doc file in a new document and not in the current doc file. So you end up having 2 separated files. I tweak it a litte bit to have it open the specified document only therefore the macro1 will be applied to the right document.
Macro
Macro2354
;run Word and open file
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application app._create
app.Visible = TRUE
Word.Documents docs=app.Documents
VARIANT d=_s.expandpath("$documents$\My Best Story.docx")
;Word.Document doc=docs.Add(d)
Word.Document doc=docs.Open(d)
;run a Word macro
app.Run("Macro1")
On the same token in Macro 2351, it did apply the macro1 on the new document but not on the current document.
so I ended up by just calling like its original version
Macro
Macro2351
;/exe 1
;Use /exe 1 to run the macro in separate process, as User.
;This macro may not work without it.
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application app._getactive
;Word.Documents docs=app.Documents
;VARIANT d=_s.expandpath("$documents$\My Best Story.docx")
;Word.Document doc=docs.Add(d)
;act "Word"
;doc.Activate
;run a Word macro
app.Run("Macro1")
Thanks a lot for your quick responses.