Solved

VBScript: Adjusting image in header using text wrapping

Posted on 2014-01-22
5
932 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 49

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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

911 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

19 Experts available now in Live!

Get 1:1 Help Now