Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
dandaanilreddy
Partner - Creator III
Partner - Creator III

How to get bold text and align image to left in word using macro

Hello Developers

I have VB script that exports images to word, but i want the chart title to be bold and the chart should be appeared to left of the word document. Please find the script below that exports images to word. Can someone help me with the requirement as i don't know VB script.

Sub ReportPossible2

    Set XWord = CreateObject("Word.Application")

    XWord.Visible=true

 

    Set DocWord = XWord.Documents.add()

                                            

                    XWord.Selection.InsertBefore "Titulo"&chr(13)

                  

                    XWord.Selection.Collapse wdCollapseEnd

                                     

                  

                  

                    ActiveDocument.ClearCache

                    ActiveDocument.GetApplication.WaitForIdle

                 

                    set image = ActiveDocument.GetSheetObject("CH02")

                    image.CopyBitmapToClipboard

                    XWord.Selection.Paste

end sub

Thanks

Anil

4 Replies
MarcoWedel

Hi,

maybe you can post this question in a forum related to MS Office rather than QlikView?

thanks

regards

Marco

tamilarasu
Champion
Champion

Hi Anil,

Try this,

Sub Test

Set XWord = CreateObject("Word.Application")

    XWord.Visible=true

    Set DocWord = XWord.Documents.add()

           With XWord.Selection                       

                    .InsertBefore "Titulo"&chr(13)

                    .Font.Bold = True

                    .Font.Color = RGB(243,58,160)

                    .Font.Size = 15

                    .Font.Name = "Georgia"

                    .Collapse wdCollapseEnd

            End With

                                    

     ActiveDocument.ClearCache

     ActiveDocument.GetApplication.WaitForIdle

     set image = ActiveDocument.GetSheetObject("CH438")

      image.CopyBitmapToClipboard

     XWord.Selection.Paste

End Sub

dandaanilreddy
Partner - Creator III
Partner - Creator III
Author

Hi Nagraj

Thanks for the reply. I executed the code by changing the object id but i am not getting the image into word its fetching script into word. Please see the result below.

Titulo

Sub Test

Set XWord = CreateObject("Word.Application")

XWord.Visible=true

Set DocWord = XWord.Documents.add()

           With XWord.Selection                      

.InsertBefore "Titulo"&chr(13)

.Font.Bold = True

.Font.Color = RGB(243,58,160)

.Font.Size = 15

.Font.Name = "Georgia"

.Collapse wdCollapseEnd

End With

                                   

ActiveDocument.ClearCache

ActiveDocument.GetApplication.WaitForIdle

     set image = ActiveDocument.GetSheetObject("CH438")

image.CopyBitmapToClipboard

XWord.Selection.Paste

End Sub

Thanks

Anil

dandaanilreddy
Partner - Creator III
Partner - Creator III
Author

Hi Nagraj

I made the changes to the script and now its exporting the image to word but i tried to get 2 objects into word the title of the second image is showing to the right side on the word document i want that to be at left side. Can you please help me . Please see the script below.

Sub Test

Set XWord = CreateObject("Word.Application")

XWord.Visible=true

Set DocWord = XWord.Documents.add()

           With XWord.Selection                     

.InsertBefore "Titulo"&chr(13)

.Font.Bold = True

.Font.Color = RGB(243,58,160)

.Font.Size = 15

.Font.Name = "Georgia"

.Collapse wdCollapseEnd

End With

                   

                   

                    ActiveDocument.ClearCache

                    ActiveDocument.GetApplication.WaitForIdle

                  

                    set image = ActiveDocument.GetSheetObject("CH824")

                    image.CopyBitmapToClipboard

                    XWord.Selection.Paste

                   

                   

                    XWord.Selection.InsertBefore "My Chart"&chr(13)

                    XWord.Selection.Collapse wdCollapseEnd

                    XWord.Selection.InsertBefore chr(13)

                    XWord.Selection.Collapse wdCollapseEnd

                    XWord.Selection.InsertBefore chr(13)

                    XWord.Selection.Collapse wdCollapseEnd

                    XWord.Selection.InsertBefore chr(13)

                    XWord.Selection.Collapse wdCollapseEnd

                    XWord.Selection.InsertBefore chr(13)

                    XWord.Selection.Collapse wdCollapseEnd

                         

                 set image = ActiveDocument.GetSheetObject("CH824")

                    image.CopyBitmapToClipboard

                    XWord.Selection.Paste

Thanks

Anil