Opening Word (from Outlook VBA) in Safe Mode -
i have word document attachment email need data out of pass url. i'm saving attachment local temp file, opening document, , using word object model pull data out of tables in document.
i'm having couple of problems when opening document in vba: firstly it's slow because have corporate macro stuff loads when word opens; , secondly if there messages ping when word opens (such document recovery stuff), code hangs , word never closed.
so, question can open word in safe mode vba nothing bare bones document available (because that's need)? or, there better way of controlling word gets around issues i'm having?
perhaps use shell open in safe mode, say:
"c:\program files\microsoft office\office11\winword.exe" /a
then use getobject instance.
more details:
dim wd object dim strword string, strdoc string dim intsection integer dim inttries integer on error goto errorhandler strword = "c:\program files\microsoft office\office11\winword.exe" strdoc = "c:\docs\adoc.doc" shell """" & strword & """ /a", vbminimizedfocus ''set focus other word document ''see http://support.microsoft.com/kb/238610 forms!myform.setfocus intsection = 1 ''attempting getobject... set wd = getobject(, "word.application") intsection = 0 ''resume normal error handling wd.documents.open strdoc ''code here set wd = nothing ''exit procedure: exit sub errorhandler: if intsection = 1 inttries = inttries + 1 if inttries < 20 sleep 500 '' wait 1/2 seconds resume ''resume code @ getobject line else msgbox "getobject still failing. process ended.", _ vbmsgboxsetforeground end if else ''intsection = 0 use normal error handling: msgbox error$ end if
for sleep, needs go @ top of module:
private declare sub sleep lib "kernel32" _ (byval dwmilliseconds long)
/a starts word , prevents add-ins , global templates (including normal template) being loaded automatically.
the /a switch locks setting files; is, setting files cannot read or modified if use switch.
Comments
Post a Comment