Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Macro to paste Text Object in Word

Hi to everyone,

I'm trying to paste a Text Object (all object with style and font) to a Microsoft Word document. I tried a lof of things and search in community but I can't do it...


My macro is:

sub WordExport

        Set objWord = CreateObject("Word.Application")

        objWord.visible = false

        set objDoc=objWord.Documents.add

        Const wdOrientLandscape = 1

        objDoc.PageSetup.Orientation = wdOrientLandscape

        ActiveDocument.GetSheetObject("TX01").CopyTextToClipboard true

        ActiveDocument.GetSheetObject("CH01").CopyTableToClipboard true

        objWord.Selection.Paste

        objDoc.SaveAs "C:\Daniel\Pruebas\PruebaMacro2"

        objWord.Quit

       

end sub

So, I'm trying to copy objects TX01 and CH01 in word document. When I execute the macro, it doesn't work and doesn't show any error on screen...


Can anybody help me?


Thanks in advance!

1 Solution

Accepted Solutions
marcus_sommer

This worked.

- Marcus

View solution in original post

6 Replies
Anonymous
Not applicable
Author

Hi,

I tried your macro just for TX01, and it gave me the error:

ActiveX component can't create object: 'Word.Application'

for the row     Set objWord = CreateObject("Word.Application")

I don't know if this information can be usefull for you...

Elena

Anonymous
Not applicable
Author

Thanks Elena for your answer.

I tried, and I can create this object. Probably, you don't have permission to allow System Acces, so change Macro security and try again.

marcus_sommer

This worked.

- Marcus

Anonymous
Not applicable
Author

Hi Marcus,

Thanks! Works like a charm!

But why? I tried to understand and I think that the problem was:

ActiveDocument.GetSheetObject("TX01").CopyTextToClipboard 'true

So, in my macro I was given a 'true' parameter that didn't need. Is this the reason?

Thanks.

Best regards,

Daniel

marcus_sommer

Yes, CopyTextToClipboard had in opposite to CopyTableToClipboard no second parameter. You could see such things with examples in the APIGuide.qvw in your install-folder.

- Marcus

Anonymous
Not applicable
Author

Thanks Marcus for your help!

Best regards,

Daniel