Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBScript: Adjusting image in header using text wrapping

Posted on 2014-01-22
5
Medium Priority
?
1,036 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 53

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 53

Accepted Solution

by:
Rgonzo1971 earned 2000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

609 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