Solved

VBScript: Adjusting image in header using text wrapping

Posted on 2014-01-22
5
959 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 50

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 50

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

821 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