I am currently using VBA code which was originally intended for an excel document. I could just retailor the code for use in word but I think it might be better to extend the application so that it is compatible to ‘potentially’ any MS Office Application. But I’m not entirely sure how to do so.
For example the excel based code fetches the document’s path:
If libDir = "" Then libDir = ThisWorkbook.Path
To extend this to word I just have to replace ThisWorkbook with ActiveDocument.
But would it be possible to find out which office application is running the VBA code so that I can keep both.
'IF VBA run from Word Then
If libDir = "" Then libDir = ThisWorkbook.Path
'ELSE VBA run from Excel then
If libDir = "" Then libDir = ActiveDocument.path
'End If
So far I can see that I can find out if word or excel is open but I cannot assume that because it is open it is running that specific module. But that is beyond my VBA knowledge.
I’ve also tried this currentproject.path but that doesn’t work.
Thanks in advance
It does sound complex trying to tool up code to suit various Office APPs. And what does this code do if it can be applied in word and excel – perhaps vbscript and then automating the object you want to work with is an option
On your specific example above, it will actually compile okay (and I haved tested in xl2003, xl2010 and word2010), so with error handling the code will run and skip the otherwise problematic areas.
Something else to consider, the Path wont exist if the file is unsaved.