vba - How to run macro in word without opening it? -


how run macro in word without opening it. went through same question asked before.
solution is:

dim word     dim worddoc  set word = createobject("word.application")     word.visible = false  set worddoc = word.documents.open("d:\working_folder\abc.doc")     word.run "<macroname>"     worddoc.save  word.quit         set worddoc = nothing set word = nothing 

this working me in case file name specific ("abc.doc").

what if want run macro word files in same folder?
macro defined in files, want know how filenames in folder.

untested, this:

dim word, fldr, f     dim worddoc  set word = createobject("word.application")     word.visible = false  fldr = "d:\working_folder\" f = dir(fldr & "*.doc*")  while f<>""      set worddoc = word.documents.open(fldr & f)         word.run "<macroname>"         worddoc.save     worddoc.close     f = dir()  loop  word.quit         set worddoc = nothing set word = nothing 

you can't run macro without opening file contains though.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -