Dedicated Clipboard in VBA? (1 Viewer)

ChislePip

Registered User.
Local time
Tomorrow, 01:45
Joined
Mar 14, 2014
Messages
14
I've developed VBA code in Access 2007 to copy many small Word documents into a larger Word document. It works fine, but can take 10 to 20 minutes to complete, running in the background. That's OK too! HOWEVER, because I use ".Selection.Copy" & "Selection.PasteAndFormat" as the basis for the code, it means that no other applications can use the Clipboard without conflicting with the routine running in the background.
I want to know whether there are any techniques or tools which would enable the VBA code running in the background to use some 'dedicated' Clipboard thereby freeing up any other copy and paste activities used by other applications?

My code, if it helps, looks like this:

Code:
 For i = 0 to big_number
      With objApp
            'Open next document and copy content
            strFileName = argFileNames(i)
            Set docTemp = .Documents.Open(strFileName)
            .Selection.wholestory
            .Selection.Copy
               
            'Switch back to Base document and paste content of current doc
            .Documents(strDocBase).Activate
            .Selection.endkey wdStory
            .Selection.PasteAndFormat (wdPasteDefault)
              
            docTemp.Close SaveChanges:=wdDoNotSaveChanges
              
        End With
 next i
 

Isskint

Slowly Developing
Local time
Today, 16:45
Joined
Apr 25, 2012
Messages
1,302
I would think not.

However have you considered "merging" each document into a master?

Have a look at this thread.
 

Bilbo_Baggins_Esq

Registered User.
Local time
Today, 10:45
Joined
Jul 5, 2007
Messages
586
Is there formatting and/or non-text items in the small word documents which you wish/need to retain when placed in the larger document?

If there is ONLY formatting, and it preserved/restored your other application's access to clipboard, would you be ok with reformatting once everything was in the larger document?
 

ChislePip

Registered User.
Local time
Tomorrow, 01:45
Joined
Mar 14, 2014
Messages
14
Thanks to Bilbo_Baggins_Esq and Isskint for their responses. Yes, the small documents contain images, tables and many many styles which I need to bring across. I also need to apply logic in determining which documents to use. So, it is going to be too complicated to apply the formatting after the compilation of documents. The suggestion of a 'merge' seems interesting. I'll try that shortly when I get back to work.
 

ChislePip

Registered User.
Local time
Tomorrow, 01:45
Joined
Mar 14, 2014
Messages
14
Isskint, thanks for the tip. I tried it by using the following code:

Code:
    myPathBase = myPath & strDocBase
    strFullPathFileName(0) = myPath & strDoc1
    strFullPathFileName(1) = myPath & strDoc2
    strFullPathFileName(2) = myPath & strDoc3
    Set objApp = CreateObject("Word.Application")
    objApp.Visible = True
 
    'Open base document & 'activate' it
    Set docInput = objApp.Documents.Open(myPathBase)
    objApp.Documents(myPathBase).Activate
    For i = 0 To 2
        objApp.ScreenUpdating = False
        docInput.Merge FileName:=strFullPathFileName(i), _
        MergeTarget:=wdMergeTargetSelected, DetectFormatChanges:=False, _
        UseFormattingFrom:=wdFormattingFromCurrent, AddToRecentFiles:=False
    Next i

But, the merge method is doing just that - merging documents a la 'compare' - but not appending each file to the end.

Any other ideas that don't use the clipboard?
 

Users who are viewing this thread

Top Bottom