Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Center Align An Image In Word

I'm using the following code to insert a picture into a word document:

Set myImage = wordApp.Selection.InlineShapes.AddPicture(gFileName, False, True)
With myImage[indent].Height = .Height * (maxWidth / .Width)
.Width = maxWidth[/indent]End With

How can I center this image in the document?

I put:

wordApp.Selection.ParagraphFormat.Alignment = 1
after that code but it doesn't center align it...

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
[VBA WORD] Center-align A Few Columns Of A Table
Hello all
I have a table with 4 rows and 3 columns (variable tbl) and I need to center-align all these columns, but the first one. I tried that :

ThisDocument.Range(tbl.Cell(1, 2).Range.Start, tbl.Cell(4, 3).Range.End).ParagraphFormat.Alignment = wdAlignParagraphCenter
Unfortunately, the text is centered in all the cells but the cell in the upper-left corner. That is, there is some cells in the first column which are affected by the macro. Did I missed something ? What should I do tho keep the cells of the first colum left-aligned ?

Thanks a lot for your help

PS: Sorry for my bad english


Center Align In A Flexgrid
Hi all,

I have been messing around with the Flexgrid recently and decided to make a version of noughts and crosses using the grid. Its working well with the computer able to play and now I am starting to make a network version of it but the problem I have is that when the computer makes a move the "O" does not center. My code (inside a Timer):

If Not cmdPlay2.Caption = "Your Move" Then Exit Sub


' O placement code

If Not flxGrid.TextMatrix(aa, bb) = "" Then GoTo top

flxGrid.TextMatrix(aa, bb) = "O"
flxGrid.CellAlignment = flexAlignCenterCenter
Play1.Enabled = True
Play1.Caption = "Your Move"
Play2.Caption = "Wait!"
Play2.Enabled = False

Using the flxGrid.CellAlignment = flexAlignCenterCenter for the human player works fine. The human player code is executed when the Flexgrid is clicked on whereas the CPU code is executed inside the Timer.

Anyone see or know why the "O" is not centering inside the timer?


Verticaly Center Align
is it possible to get the text in a label to vertically center align?


| |
|Have the text here |

|Instead of like this |
| |

thanks in advance

Printing Center Align
You all have seen the center aling in Microsoft Word.
How can i do the same and then print a string from a textbox or richbox?

Center Align Only First Item In Combo Box

How would I go about centering the first item in the combo box, while the rest is left aligned?


Align Form Picture On Center
Dear friends,

I've a Form that has Picture Property with a image.
This image is smaller than the Form.
How I do to automatically put this imagen in the center of the Form?
Thanks and sorry about my bad english

Center Align The Datagrid Header
Can you teach me how to center-align the datagrid header. Somehow I manage to center the data but cant figure out how to center align the header.

Please help me.

Printer.Print Center Align?
I know RSet is for right align and LSet for left align, but is there anything for center align? Please advise if you can. Thanks.

Added green "resolved" checkmark - Hack

How To Center-align The Message In MsgBox?
Pls advise as stated in title. Thanks.

Align A Cell Content To Center
How do i align a cell content to center? Thanks!


Seek and you shall find...

Align A Form Center To Page On All Resolutions.

How would i make a form be positioned in the direct center of the screen, so that no matter what resolution it would still be center.



Align Form Background Picture On Center
Dear friends,

I've a Form that has Background Picture Property with a image.
This image is smaller than the Form.
How I do to automatically put this imagen in the center of the Form?

Thanks and sorry about my bad english

Center Align Text On VB Print Output
How does one center align text on a print output from VB rather than using X Y coordinates?  This is what I have so far, but I would like the two lines of text to always center no matter what part number prints... tia.  Maureen

iNumCopies = 1
LoadLbl = MsgBox("Large " & Lblinternaldel & " label required for " & Lblrscitemno & ".  Load label stock in Printer.", 1, "AUME Special Label")
        If LoadLbl = 2 Then GoTo errHandler
        CommonDialog1.CancelError = True
        On Error GoTo errHandler
        CommonDialog1.FromPage = 1
        CommonDialog1.ToPage = 1
        NumCopies = CommonDialog1.Copies
        For iNumCopies = 1 To NumCopies
            On Error GoTo 0
            Printer.Orientation = 2    '2 = Landscape
            Printer.FontName = "Arial"
????        Printer.CurrentX = 800
????        Printer.CurrentY = 2000
            Printer.FontSize = 150
            Printer.FontBold = True
            Printer.Print Lblcustitemno
????        Printer.CurrentX = 4600
????        Printer.CurrentY = 6000
            Printer.FontSize = 160
            Printer.FontBold = True
            Printer.Print Format(Lblqty, "#####0")
        Next iNumCopies

Load, Resize And Center Image In Image Control?
I would like to create thumbnails quickly. I have used the method of loading an image into an image control, getting it's size to determine the ratio, and resize it but it's too slow.

I understand you can acheive much faster results using the StretchBlt api. However, I don't have the slightest clue on how to do it.

Here's what I would like to accomplish:

Load an image at run-time into an image control and have it resize and center quickly, maintaining the correct aspect ratio of the original image.

I would appreciate it if you could post some sample code or point me in the right direction..



How To Place Image In The Center Of Image Box
Hi all
My next question is that
I am using a picture box and a image box is in the picture box when image is appearing then it is coming at the left side
Any idea u have that how to place a image in the center of the image box

My coding are as follow:

VB Code:
Private Sub Image1_Click()Dim FileName1CommonDialog1.Filter = "*.bmp,*.gif,*.jpg,*.JPEG"CommonDialog1.DefaultExt = "*.bmp,*.gif,*.jpg,*.JPEG"CommonDialog1.ShowOpenIf CommonDialog1.FileName <> "" Then    FileName1 = CommonDialog1.FileName        If FileLen(FileName1) > 16000 Then        MsgBox "Please Check Image Size Again...", vbInformation, "Incorrect Size Of Image"        Else        Image1 = LoadPicture(FileName1)        End IfElse    FileName1 = ""End IfEnd Sub

Align Caption To Right Of Image In Command Button
This is driving me nuts.

I need to right align a caption in a command button so that it appears next to the image rather than below it.
I have seen a workaround somewhere but didn't think to save it at the time (Doh!)

Do any of you gurus know how to do it.?


<font color=blue>I once had an itch that I scratched and off fell my leg.</font color=blue>

Center Image
How do you center an image on a form?

Align Range To Ms Word?

I want to generate letters with the testresults for our patients.

this is what i have so far:

dim ObjSelectie as Range

set ObjSelectie = (start := ObjWord.ActiveDocument.content.start, end := ObjWord.ActiveDocument.content.end)

ObjSelectie.bold = true

Now i got the text in my worddocument and it is bold, i'd like to align it right though...can anyone give me the command or the method do do it? thanks...

merry christmas

Center Cursor Image
is it possible to have the cursor point to the center of the cursor image?
(offset the cursor image about 10 pixels up/left from the pointer...)

Center Image In Form
can anyone help me? how to make the image or picture at center in form while run it. please help me?


Align Content Of Footer In Word
Hi all,

I am creating a word document through vb6 and I am stuck in aligning some of the objects in the footer. The outcome should be a copyright notice inside a border and below that a logo should appaer. The problem now is that the logo appears inside the border together with the copyright notice. I managed rto get them into two different "cells", but still there are some borders which are not supposed to be there.

Any clues? I have searched and searched, but could't find that much relating to this issue...

With oDoc
.Range.Font.Name = "Arial"
.Range.Font.Size = "9"
.PageSetup.TopMargin = oWord.CentimetersToPoints(2)
.PageSetup.BottomMargin = oWord.CentimetersToPoints(2)
.PageSetup.LeftMargin = oWord.CentimetersToPoints(2)
.PageSetup.RightMargin = oWord.CentimetersToPoints(2)
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = "Subsea"
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Bold = True
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Font.Name = "Arial"
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Font.Size = "20"
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Font.Color = wdColorDarkBlue
.Sections(1).Headers(wdHeaderFooterPrimary).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Sections(1).Footers(wdHeaderFooterPrimary).Range.InlineShapes.AddPicture WorkDIR & "AkerSolutions.bmp"
.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertBefore "This document contains blablabla request and in all events upon completion of use for which it was provided." & vbCr
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Font.Name = "Arial"
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Font.Size = "8"
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Borders.Enable = True
End With

Display Image In Center Of Screen
Hi guys. I have coded in Visual Basic 6 for about 3 or 4 months. That was over a year ago. So I guess you could say I'm rusty.

Anyway, in one of my applications that I am building, I ned to display an image in the center of the screen. Say my application had one form. The user would click command1 (the button) and an image would appear in the center of the screen. The user could minimize or move the form around, but the image would still stay in the same spot, the center of the screen. If you minimize or move the form, the image would still stay in the center of my display and still be visible. In other words, the iamge needs to be "not mounted" or "detached" from my form. Anyway I hope some of you VB gurus can help me out here. I'd appreciate it.

Oh, and by the way, I forgot to mention that the image needs to stay on top of any other application that may be running.

Center Image In Listview Column
I know how to get an image into the listview but is there a way to center it.
the center. The alignment in the listview control doesn't do it. Well at least it doesn't on mine.

Need Formula To Center Image And Label In A CC
I am making my own custom controls and I need a formula that will center an image and a label vertically and horizontally in a custom control...

And how would I go about detecting if a Image control currently has a picture in it?

Center An Image In The Background Of An MDI Form...
Is there a way to center a background image on an MDI form? This is for work, so I can't use any subclassing or third party controls.

How To Make The Picture Center In The Image Box?
hi all ...

how to make the picture center in the image box?
have any example?

Private Sub Form_Click()
   Dim Msg As String
   On Error Resume Next
   Height = 3990
   Width = 4890
   image1.Picture = LoadPicture("D:2003-10-282pic.jpg", vbLPCustom, vbLPColor, 32, 32)
   If Err Then
      Msg = "Couldn't find the .cur file."
      MsgBox Msg
      Exit Sub
   End If
   Msg = "Choose OK to clear the bitmap from the imagebox."
   MsgBox Msg
   image1.Picture = LoadPicture()
End Sub


How To Word Align Data In Lpbits For Use In SetBitmapBits
Hi, I am trying to render an image from height data. My Data array already has the correct information, and when i loop through and fill the BMPData array with the RGB values using my LongToRGB function (which works correctly) I get an overflow error on about the 9215th iteration of the loop... (significant number???). EDIT: this is because a byte cannot hold more than 8 bits.. i.e. decimal # > 255. But how then can I input the RGB values into byte aligned fashion....

Anyways I am trying to fill up the BMPData array with the RGB color values so that I can input this array into the SetBitmapBits call and render my image....

I know that SetBitmapBits needs the lpbits, which is an array of word aligned values,... but I am unsure of how to make my data word aligned.

The end of this subroutine should generate the bitmap and display it in picture1 (a picture box)

Any help would be greatly appreciated... i've been stuck on this for weeks trying to get this image to render.

Oh also, I dont' know if it matters or not for this code, but the image is being displayed in 32bit color.

Private Sub createimage_Click()

Debug.Print "" 'to skip a line
Debug.Print "starting..."

Dim hBmp As Long
Dim hDC As Long
Dim desthDC As Long
Dim hOldBmp As Long
Dim BMPData() As Byte

Dim increment As Long
Dim tot As Long
Dim a As Long, b As Long

ReDim BMPData(imres ^ 2) As Byte 'imres is predefined as 1024,
'but may change in the final product

tot = 0

MinMax 'call the minmax subroutine to find the min/max of the data
zsf = 128 / (max - min) 'my zscalefactor used to find the correct color value

For a = 0 To imres - 1
For b = 0 To imres - 1
increment = LongToRGB(a, b) 'get the color value
'associated with the data point
BMPData(tot) = increment
'This is where I am getting the overflow... the increment value
'at this point is 1279 which I'm pretty sure is half the problem,
'but the # has to be this big because it represents and RGB value, but a byte cannot a value > 255...

tot = tot + 1
Next b
Next a

desthDC = GetDC(Picture1.hwnd)
Debug.Print "desthDC " & desthDC

hDC = CreateCompatibleDC(desthDC)
Debug.Print "hDC " & hDC

hBmp = CreateCompatibleBitmap(hDC, imres, imres)
Debug.Print "hBmp " & hBmp

hOldBmp = SelectObject(hDC, hBmp)
Debug.Print "hOldBmp " & hOldBmp

setbitmapbits( hBmp, ????, ?????) ' I DONT KNOW THE ????'s obviously

Call StretchBlt(desthDC, 0, 0, Picture1.Width, Picture1.Height, hDC, 0, 0, imres, imres, vbSrcCopy)

'release the memory
Call SelectObject(hBmp, hDC)
Call DeleteDC(hDC)
Call ReleaseDC(Picture1.hwnd, desthDC)
Call DeleteObject(hBmp)


Debug.Print "...ending"
End Sub

How Does One Code A Image Box To Center Itself Perfectly On A Form?
How does one code a image box to center itself perfectly on a form?

I plan to have an image that will need to be centered on a maxamized form. I will need it to center no matter what resolution a user is using.

Any ides?

2 Function.. I Need Align Right (Print To Printer And Write To Word)
I have functions for generate to msword( .doc ) and print text to printer. I need to set text align right ( data is currency ).

Example ..
1.efficiency 89 %
2.size 2.5 kW
3.price 1,000 $US

number should be align right.

... some thing right that..

How can I do ?


Center Text In Word Thru VB
how do you set text to be center in MS Word thru VB?

How Can Make Center Part Of Form Appear Scroll Bar When Center Element Are Too Many?
How can make center part of form appear scroll bar when center element are too many..??

Word Text Boxes Align Text?
Is there a way of aligning text to bottom in a text box like you can in the cell of a table?


Saving A Word Image Via The Ole Messes Up Word - Heellllp!!
I'm getting an odd problem I'm hoping someone can help me on. I have some word documents that have been saved into the DB as images. I'm using an OLE container, bound to a RDO remote data control, to pull the image out of the DB and then save it as a word document. Trouble is, every time I issue a 'oleObject.object.SaveAs xstrFileName', it adjust all of words settings so that the next time word opens it appears on a tiny tab at the top left of the screen. Even worse, although I can resize the tab vertically it won't let me resize horizontally, so I can't even drag it back onto the screen to look at it. At the moment the only way I can get word backonto the screen is to restart windows!

Here's the code that saves the object:-

Private Sub pcExportObject(xstrObjectRef As String, xstrFileName As String)
Dim strSQL As String, rstObject As rdoResultset
On Error GoTo errorHandler
'get the object
Let strSQL = "Select * from qb2_objects where xk_object_ref = " & xstrObjectRef
Set rstObject = rdoFaim.OpenResultset(strSQL, gvarHamOpenMode, gvarHamLockMode)

'clear the OLE and populate the dataset
Let oleObject.DataField = ""
Set dtaData.Resultset = rstObject

'put the object into the ole
Let oleObject.DataField = "xk_object_data"

'save the ole (and therefore the object) to disk
Me.oleObject.object.SaveAs xstrFileName

On Error Resume Next
Set rstObject = Nothing
'error handled by calling routine
Err.Raise Err.Number, Err.Source, Err.description, Err.HelpFile, Err.HelpContext
End Sub

Any ideas, I'm a bit desperate on this one.

DB Image To MS Word......?
Hello Guys

Anybody know how to load an image from SQL Server into a MS word document?? Any ideas which classes from the Word library i can use to achieve this?

Many thanks

Image Into Word?

I have an image stored in a database that I need to insert into a document I am printing from word.

I know the code used to paste an image using the filename but how do you paste an image into word given the table and field name? (tblDefaults, Logo)


Select An Image In Word

i need to select an image in Word so that my vb6 app can alter the options of it. I've tried it when recording a macro but then i can't select the image. The image is automaticly inserted with a piece of code which is shown below. The option that i need to alter is to send the image to the back (msoSendToBack i believe).
I hope someone can help me, this is a really big problem for me.

The program searches a table for a certain piece of "code" which is replaced when it's found.

For i = 1 To objDoc.Tables.Count 'Search every table in the document.
With objWord.Selection
.Find.MatchWholeWord = False
.Find.MatchCase = False
.Find.MatchWildcards = True
If .Find.Execute(FindText:=searchtext) = True Then
ModuleType = objDoc.Tables(i).Cell(2, 2)
ModuleType = Mid$(ModuleType, 2, 3) 'Filter the code
vervang_word 'replace code with image link
With Dialogs(wdDialogInsertPicture) 'Use the link to insert the picture
.Name = Vervanging
.Application.Selection.ShapeRange.Fill.Visible = False
End With
End If
End With

Resize Image In Word
I'm writing a macro with VBA. It's working perfectly except for one thing... resizing the image.

Here's how it works: There's a field code in the document. The user double-clicks on the field code to run the macro. The macro allows a user to select an image. Then it inserts that image, centers it, and (in theory) changes the size. That's where the problem is... changing the size.

If you're doing this manually: Once you've inserted the image, you double-click on the image (to open the Format Picture dialog box). Then you click on the Size tab, then you can edit either the Width or Height. Lock Aspect Ratio is automatically checked by default, so changing a value in the Width or Height fields will automatically update the other one.

Why it's important to me: Users will be inserting images of various shapes and sizes, but I want to specify that the Width should always be x and let the Height update so I don't lose the original ratio.

Here's the code. Any suggestions?
Sub InsertImagesIntoReport()
On Error GoTo Err_InsertImagesIntoReport
Dim sFileName As String
Dim ilImage As InlineShape

' Display browse window
With Dialogs(wdDialogInsertPicture)
If .Name <> "" Then
sFileName = .Name
Exit Sub
End If
End With

' Remove field code
If Selection.Type = wdSelectionNormal Then
End If

' Insert and format picture
Set ilImage = Selection.InlineShapes.AddPicture(sFileName, False, True)
With ilImage
.LockAspectRatio = msoTrue
.Width = MillimetersToPoints(117.33)
End With

' Center image
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

Exit Sub
MsgBox Err.Description
End Sub

Image Manipulation In MS Word Using VBA
I am trying to add an image to a document for a signature. The position of the signature will change slightly from time to time. I would like to use a picturebox in a MS word document to insert an image into a document using code but have been unable to figure out the properties/methods of a picturebox in MS word work.

I'm able to add an image at a certain location using code similar to:

Selection.InlineShapes.AddPicture _
FileName:=FormUserForm.txtPictureFile.Text, _
LinkToFile:=False, SaveWithDocument:=True

When the image is added it displaces the text, which I do not want it to do. I want the image inserted and formated to be behind the text so the text does NOT move. Moving the text back up only moves the image up also.

Is there a way to manipulate the image beyond the code above??....Like "Format.Layout.BehindText" type of statement??

Insert Image On Word
Hi all, hope that with your help i could solve my problem
Im pretty new so i will explain my problem as detailed as i can. Im working in a program with vba the program is arcmap. I have made a button that creates a report in word showing some values of a table i have in arcmap, this works ok. The problem is that i have to insert an image as well. I have the full path of the image and i need to insert it on word. I have create the report via bookmarks. How can i solve this?
any help would be greatly appreciated

Placing An Image Into A Word Doc
To all,

While this question might appear similar to many other threads on this forum, it is a bit different. I have been researching this for a day without success. I have 900 GIF files that I want to programatically put together into one word doc, one gif per page. The problem I am having is centering each GIF onto the page. I have the S/W to insert the image and resize it, combine the pages, etc., but I haven't figured out how to perform both the vertical and horizontal centering. the goal here is to make the GIF as large as possible while maintaining the same aspect ratio and centering it on the page. A snippet of my code is as follows:

Dim oWordDoc As Object
Dim oWordApp As Word.Application
Dim oWordInline As Object
dim sImageFile As string

sImageFile = "c: est.gif"

Set oWordApp = New Word.Application

' the following opens my template - it is a blank doc with all borders are set to 1 inch and a footer
Set oWordDoc = oWordApp.Documents.Open("c:ImageTemplate.doc", 0, 1)

' the following statement will set the horizonal alignment to center, but NOT the vertical
' oWordDoc.Range(0).ParagraphFormat.Alignment = wdAlignParagraphCenter

' insert the gif
Set oWordInline = oWordDoc.Range(0).InlineShapes.AddPicture(sImageFile, False, True)

With oWordInline

' compute the new width and height sizes for optimal sizing


End With

' All the other stuff, saving and closing the doc, setting the necessary values to NOTHING, etc. ...

Any code examples would be GREATLY appreciated ...

Thanks in advance,


Loading An Image To MS Word
I have my solution now, but i still have one more thing... Loading an image to MS Word thru VB6, how to do this?

Please please please again help me...

Image On Word Document Through VB6...
i want to paste a imge on a word document through VB6, kindly anyone guide me about it... image z in jpg form and its path z saved in DB.

hope for the Favor
thnx and regards,

How To Save An Image To A Word Doc
i have a barcode in an image and need to print it to a specific area on a word file along with various text. The text is not a problem but the image is. I want to write the image to a bookmark, can anyone help me?

Insert Image In Word

Is it possible to insert an image into a word document using the Word API? Can any one please give some sample on that.


Inserting An Image Into Word

I am printing a 'confirmation letter' in Microsoft Word from VB. I am loading all the contents of this letter dynamically and I have everything working except for the company logo.

How do you insert an image into the TOP LEFT corner of microsoft word, forcing any text to wrap around it on the right?

I have tried making a macro in word and then copying the vba code but the image never gets copied to the top left corner.

Please help!

WORD Image Insert?
Is there a way I can get the path of the image inserted into word? I create the instance of word from vb and embed word in a vb form.

Thanks in advance

Image Transfer To Word Using VB
 Plz...... It is an emergency.
How to paste jpg images stored in a windows folder to a MS word document ,after other using VB 6.0.(in a single Ms word document using page break).

VBA Word Image Handling
I am working on converting Word to HTML tags. Don't know how to look for the image in Word document and then convert to img tag. Any Clues !

Sending Image Into MS-Word
Hi gurus!
I have some question.
I made a MS-Word template as a
In MS-Word template, I made a picture box at designated position.
In VB program, I want to insert into MS-Word template's picture box.
For example, in VB program, give the image file path "C:image.jpg" to MS Word and MS Word have to display the image.
In case of this, What MS Word object and property, method do I have to use?
Could anyone let me know?


Copyright 2005-08, All rights reserved