Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Can a macro start when copying a document? (Office XP, Word 2002)

    Hi,

    Is there an event I can use to start a macro when I copy a file from one folder to another? (Drag & Drop)

    F. example the AutoOpen macro automatically starts when a document is opened. But I haven't found anything that I can use when a file is copied to another place.

    Can anyone help?

    regards
    Bjorn

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    Copying or moving a file from one folder to another has nothing to do with Word. It is done at the Windows (Explorer) level, and Word is not necessarily active while you do it (it need not even be installed <img src=/S/grin.gif border=0 alt=grin width=15 height=15>.) So there is no way to trigger a Word macro when you copy a file.

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    I'm curious why you need to do this. Are there some paths in the document (e.g., fields) or in code that will need to be updated? Maybe there is another solution.

  4. #4
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    Hopefully!

    jsher! You have answered my problem earlier. 231037

    My problem:

    We use SharePoint (SP) to store documents(files). SP gives a document a version number. To day I can get hold of that version number by using a VBA macro in my template. It works OK as long as I use Windows Explorer to open the document/file, then the Document_Open macro starts. I cannot get the version number unless I open the document, NOT when copying it. SP does not store the version number in the document (as far as I have experienced).

    When I open the document from a browser (e.g. IE) or SharePoint, which is "web-interface", the Document_Open macro will not start. And also the document opened always is shown with the name: "Document in Microsoft Internet Explorer" ( a temp file).

    I can change the registry key: HKEY_LOCAL_MACHINE/SOFTWARE/Classes/Word.Document.8 value from 9 to a (hex) and then the document opens with the correct filename and is workable, BUT the Document_Open macro will not run!

    I have solved this by making a macro that opens the document through WindExplorer and then get the macro that collects the version number to run.

    I have also used: "App_WindowSelectionChange(ByVal Sel As Selection)" to start when clicking in the document, but this is not possible unless the following macro has run:

    Public Sub Register_Event_Handler()
    Set ProtectHandler.App = Word.Application
    End Sub

    ......... and no macro will run when I open a document from SP or a browser.

    Any suggestion to my and many other persons's problem??

    I don't understand why Microsoft cannot provide a Field Code or a property to make this possible!

    Thanks for your interest, I appreciate it very much!


    regards a frustrated
    Bjorn

  5. #5
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    Hi HansV,

    Please see my answer to jscher2000

    Any suggestions?

    Regards
    Bjorn

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    Frankly, no, except for a probably naive one:

    Does it help if you start Word normally (so that the application event handlers are initialized) and then keep Word open all the time?

    Otherwise, this is out of my league.

  7. #7
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    Hi HansV,
    Well Word is running, but the application event handlers are not started when Word starts. they start when the document is opened.

    I thought that it might be unwise to start the application event handlers as soon as Word is running. I've been told that it takes to much memory and can cause other problems(??)

    If I start the application event handlers by using the AutoExec macro, will that work for documents that are opened later?

    Regards
    Bjorn

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    Bjorn,

    Why don't you test it? From a distance, it's hard to predict whether activating application level event handling with Word will have negative effects in your situation - it depends on the hardware, on the OS, on other software running etc.

  9. #9
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    Thanks Hans I shall.

    I have been told that it is good practice to unload such application event handlers.
    On the other hand, when I have one document open and the application event handlers are initiated it seems not to have any effect on other documents that are opened.
    But I will test it.

    Thanks!

    Bjorn

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    > SP gives a document a version number. To day I can get hold of that version number by using a VBA macro in my template.
    > It works OK as long as I use Windows Explorer to open the document/file, then the Document_Open macro starts.
    > I cannot get the version number unless I open the document, NOT when copying it. SP does not store the version number
    > in the document (as far as I have experienced).

    I find it odd that the version number is neither in the document nor in the document file name. Could SharePoint might be stashing it somewhere nonobvious? Our DMS hides the version number in a notation at the end of the Title field in the document properties, for example.

    But I'm still not clear: after copying the file, why is the version number needed for the copy?

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    The easiest way to insert a link to another post in a message is to click the 1-Click TagPanel, and then click one of the two "Post" buttons. After that, you only have to substitute the correct number, and in the second case, a description.
    It is also easy to type the tag yourself: <!t>[post#=231037]<!/t> will result in <post#=231037>post 231037</post#>. See <!help=19>Help 19<!/help>.

  12. #12
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    Hi jscher2000,

    Thanks for your interest!!

    From SharePoint (SP) I can retrieve the version number using a macro containing: SPS_GetVersion = objRS.Fields("urn:schemas-microsoft-comublishing:FriendlyVersionID").Value
    But this is only available when I open the document, i.e. can run a Document_Open macro

    In our business, as in any other for that matter, the document in use, e. g. a specification, is precious and in order to be sure that one are working with the valid version, the version number is telling you which version number you are working with. You then can check with the original whether it is the latest/correct version or not. (Comment: Data has made it more important to be very accurate in handling document than before, simply because the freedom is huge and the alternatives are numerious)

    I would have expected that Microsoft had provided a property/field code or a simular "thing" such that the version number could be placed in the document, may be the same way as your DMS (?). But so far nobody has told me and I haven't found any information about that on TechNet, Knowledge base, SharePoint user group: http://communities.microsoft.com/Newsgroup...p;iPageNumber=1

    Again thanks! It helps to get frustration out and explained.

    Then back to the problem:
    In order to overcome this problem I have inserted a macro as shown part of above that inserts the version number. But this macro will not run unless the Document_Open automacro has run. This starts the macro for collecting the version number. Then copying omit this function. Therefore it would be useful if a click in the document could start the macro collecting the version number.

    I have used this click event in order to start a UserForm (and also in another situation):
    "Public WithEvents App As Word.Application" and "Private ProtectHandler As New EventClassModule" are defined and this macro: Public Sub

    Register_Event_Handler()
    Set ProtectHandler.App = Word.Application
    End Sub

    To get the application event handler to be initialized the Document_Open macro must start. So I'm back to "the drawing table" again.

    This situation is also occur when I open the file from SP, a web-interface, then the document name becomes "Document in Microsoft Internet Explorer" and the whole story repeats: no macro will start!

    Well, I have to continue, also with Microsoft to try to solve this problem (or may be change our DMS?)

    See also post <!post=231037,231037>231037<!/post>.
    (How to insert a hyperlink to this number?) That's <!t>[post=231037,231037]<!/t> -Mod.

    Thanks jscher2000

    regards
    Bjorn

  13. #13
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    As you may know, Sub FileSave(), Sub FileSaveAs(), Sub FileClose(), etc., do not require event handling to be enabled. If the document identification parameter used to return the objRS from SharePoint is the file path, then you should be able to retrieve it at the point of Save or Save As. Copying is more difficult, because the path will have changed. The only workaround that seems available is to store a LastPath document property or variable and constantly update that. Big hassle, but many DMS's do this, so it's not such an uncommon workaround.

  14. #14
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    Thanks a lot. I'l do that the next time I need to.

    Regards
    Bjorn

  15. #15
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Can a macro start when copying a document? (Office XP, Word 2002)

    Thanks jscher2000!!

    This can solve a lot of headaches. It will also solve the copy problem, since, if, the version number can be put into the document when checking in, it will be there when copying it to another location.

    Though I have some doubts, it looks like SharePoint first save the document then mark it with the version number after the check-in has occured. Well, I will test it out soon.

    Thanks!

    Regards
    Bjorn

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •