Solved

VBScript: Adjusting image in header using text wrapping

Posted on 2014-01-22
5
918 Views
Last Modified: 2014-01-23
Hello experts,

I am trying to programmically adjust an image placed in the header of my Word document.  I would like to use the feature "text wrapping" and choose the "square" option.  This will format my header properly.  However, even recording a macro the "text wrapping" feature is disabled.

Here is my code and attached doc.


Option Explicit

Dim objWord
Dim objDoc
Dim objSection
Dim objSelection
Dim objPageNumbers


Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("C:\Documents and Settings\lspaz\Desktop\Test XXX.docx")
Set objSection = objDoc.Sections(1)
Set objSelection = objWord.Selection
Set objPageNumbers = objSection.Footers(1).PageNumbers
	
Const wdPageBreak = 7
Const wdPageNumberStyleUppercaseRoman = 1


HeaderAdjuster

Sub HeaderAdjuster()


add code


End Sub

Open in new window


TEST-DOC.docx

Thank you!
0
Comment
Question by:Maliki Hassani
  • 3
  • 2
5 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 39802386
HI,

pls try
Set hdr = objDoc.Sections(1).Headers(wdHeaderFooterPrimary)
Set ilshp = hdr.Range.InlineShapes(1)
Set shp = ilshp.ConvertToShape
shp.WrapFormat.Type = 0 'wdWrapSquare

Open in new window

Regards
0
 

Author Comment

by:Maliki Hassani
ID: 39803830
Thank you Rgonozo1971,

I am getting a runtime error:
Variable is undefined: 'wdHeaderFooterPrimary'
Any ideas what I am doing wrong?

Option Explicit

Dim objWord
Dim objDoc
Dim hdr
Dim ilshp
Dim shp


Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("C:\XXX.docx")


Header


Sub Header()

Set hdr = objDoc.Sections(1).Headers(wdHeaderFooterPrimary)
Set ilshp = hdr.Range.InlineShapes(1)
Set shp = ilshp.ConvertToShape

shp.WrapFormat.Type = 0 'wdWrapSquare


End Sub

Open in new window

0
 

Author Comment

by:Maliki Hassani
ID: 39803855
Perhaps this can help. Not sure if this is the solution.

First. In VBS wdHeaderFooterPrimary denote literal. You must define constant.
Second. Range.Text is not object.
Modify script like this.
set bjSourcRange =  objSourcDoc.Sections(1).Headers(1).Range
wscript.echo bjSourcRange.Text
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39804092
Hi

I forgot you it' vb script

Option Explicit

Dim objWord
Dim objDoc
Dim hdr
Dim ilshp
Dim shp


Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("C:\XXX.docx")


Header


Sub Header()

Set hdr = objDoc.Sections(1).Headers(1) 'wdHeaderFooterPrimary
Set ilshp = hdr.Range.InlineShapes(1)
Set shp = ilshp.ConvertToShape

shp.WrapFormat.Type = 0 'wdWrapSquare


End Sub 

Open in new window

0
 

Author Comment

by:Maliki Hassani
ID: 39804144
Thank you, I guess I need to remove the VBA coding to make it work VBScript.  Thanks again.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now