Report macros in a batch of Word files
the problem
i have 100 word files, suspect have different macros in them.
i need find out files have macros , names of files , names macros.
i not know names of various macros might in files.
so
i need macro (or process ) check batch of word files , report name of , each macro in each file.
the type of returned data be;- file name, macro name, macro name.
for example
file named "x" has macro name "macro 1", has macro named "macro named 2"
file named y has macro named "1", has macro named "7"
file named z has macro named 8
file named y has macro named "none"
the solution need run on 100 word files stored in 1 network folder location.
you have trust programmatic access visual basic project before running macro. have once:
- click office button > word options or file > options, depending on word version.
- click trust center
- click trust center settings...
- click macro settings.
- tick check box "trust access vba project object model".
- click ok twice.
here macro:
sub listmacros() dim strfolder string dim strfile string dim docs document dim docn document dim vbc object ' vbcomponent dim lngline long dim strproc string dim strline string application.filedialog(4) ' msofiledialogfolderpicker if .show strfolder = .selecteditems(1) else msgbox "no folder specified!", vbexclamation exit sub end if end if right(strfolder, 1) <> "\" strfolder = strfolder & "\" end if application.screenupdating = false set docn = documents.add strfile = dir(strfolder & "*.doc*") while strfile <> "" if right(strfile, 4) <> "docx" set docs = documents.open(filename:=strfolder & strfile, addtorecentfiles:=false) strline = "" each vbc in docs.vbproject.vbcomponents if vbc.type = 1 ' vbext_ct_stdmodule vbc.codemodule lngline = .countofdeclarationlines + 1 until lngline >= .countoflines strproc = .procofline(lngline, 0) ' vbext_pk_proc strline = strline & ", " & strproc lngline = lngline + .proccountlines(strproc, 0) loop end end if next vbc docs.close savechanges:=false if strline <> "" strline = strfile & ":" & mid(strline, 2) docn.content.insertafter strline docn.content.insertparagraphafter end if end if strfile = dir loop application.screenupdating = true end sub
regards, hans vogelaar
Microsoft Office > Word IT Pro Discussions
Comments
Post a Comment