ole - VBA to Prevent Keyboard Input While a Package Object (XML) is Read into ADODB Stream? -
i developing application opens , reads xml document embedded in powerpoint presentation, or word document. in order read object (xmlfile object
) have do:
xmlfile.oleformat.doverb 1
this opens package object, , have subroutine gets open instance of notepad.exe, , reads contents in adodb stream.
an example of procedure available on google docs:
during process there few seconds window notepad.exe gains focus, , inadvertent keystroke may cause undesired results or error reading xml data.
i looking 1 of 2 things:
- either method prevent user inadvertently inputting (via keyboard/mouse/etc) while operation being performed. preferably not take control of user's machine
mousekeyboardtest
subroutine, below. or, - a better method of extracting xml data string variable.
for #1: function found, leery of using. wary of taking sort of control of users system. ##are there other methods might use?##
private declare function blockinput lib "user32.dll" (byval fblockit long) long private declare sub sleep lib "kernel32" (byval dwmilliseconds long) sub mousekeyboardtest() 'both keyboard , mouse blocked blockinput true ' turns off keyboard , mouse ' routine goes here sleep 5000 ' optional coding blockinput false ' turns on keyboard , mouse end sub
for #2: background, issue seems inability extract embedded object reliably using method other doverb 1
. since dealing unsaved document in application (notepad) immune vba skillz, seems way this. full background on that, here:
my understanding have control on how xml file gets embedded powerpoint presentation in first place. here not quite understand why chose keep data need contents of embedded object.
to sure, task of getting contents not piece of cake. actually, long there no (simple or moderately difficult) way call queryinterface
, use ipersist*
interfaces vba, there 1 way contents of embedded object. way involves following steps:
- activate embedded object. used
oleformat.doverb 1
that. better way calloleformat.activate
, irrelevant particular problem. - use embedded object's programming model perform useful operations getting contents, saving or whatever exposed.
notepad.exe
exposes no such programming model, , resortedwinapi
best choice available.
unfortunately, current approach has @ least 2 flaws:
- the 1 identified in question (activation of
notepad.exe
leading possibility of user's interference). - if user has default program opening
.txt
files othernotepad.exe
, approach doomed.
if have control on how embedded object created better approach store xml data in property of shape
object. use shape.alternativetext
(very straightforward use; shouldn't used if export .pptm
html or have different scenario alternativetext
matters) or shape.tags
(this 1 semantically correct task) that.
Comments
Post a Comment