Solved

VBScript: Adjusting image in header using text wrapping

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

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…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
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…

770 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