Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to set the Horizontal alignment Property of a Picture Object in a Word Document?

Posted on 2002-04-15
11
Medium Priority
?
632 Views
Last Modified: 2007-11-27
Hi,

How to set the Horizontal alignment Property of a Picture Object in a Word Document?

In a table, i add a picture. I need to set the Picture's Property (Right Click picture > Select Format Picture > go to Layout Tab > Horizontal aligment)?

I think i got the code i want but still cannot make it. Can someone guide or customize my codes a bit?

Here is the codes:

Dim myWord As New Word.Application
Dim myfileName As String

Private Sub cmdOpenWord_Click()
   
    myWord.Visible = True
    myWord.Documents.Add
   
    myWord.ActiveDocument.Tables.Add myWord.ActiveDocument.Range, txtRow, txtCol ' wdAlignTabRight ', wdAutoFitContent
    myWord.Activate
   
    'Set Border to None
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderBottom) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderDiagonalDown) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderDiagonalUp) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderHorizontal) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderLeft) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderRight) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderTop) = wdNone
    myWord.ActiveDocument.Tables(1).Borders.Item(wdBorderVertical) = wdNone
   
    'myWord.ActiveDocument.Shapes.AddPicture myfileName
    myWord.ActiveDocument.Tables(1).Cell(1, 1).Select
   
    For i = 1 To 25
        j = j & "Hello World " & Chr$(12)
    Next i
   
    myWord.ActiveDocument.Tables(1).Cell(1, 1).Range.InsertAfter j
   
    myWord.ActiveDocument.Shapes.AddPicture myfileName
    myWord.ActiveDocument.Shapes(1).WrapFormat.Side = wdWrapRight
    myWord.ActiveDocument.Shapes(1).WrapFormat.Type = wdWrapTight
   
'    myWord.ActiveDocument.Shapes(1).AutoShapeType = wdHorizontalLineAlignRight
'    myWord.ActiveDocument.Shapes(1).AutoShapeType = wdHorizontalLineAlignRight
    'myWord.ActiveDocument.Tables(1).Columns(1).Width = 120
End Sub

* I need to solve this problem before Tuesday. Points will be added to fast and accurate answer. Thanks.
0
Comment
Question by:Ryan Chong
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 54

Author Comment

by:Ryan Chong
ID: 6943591
Anybody.. ?
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6947127
ping

Busy now, check with you later.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6947501
Hi,
I don't see Layout Tab (in Word 97), but you can do this:

1. go to menu Tools, Macro, select "Record new Macro"
2. Macro recorder is running and whatever you do will be recorded.  Now, select Layout Tab and do the alignment of the picture.
3. Stop Recording
4. Now, in the list of macros, select your macro and press Edit - this will show the generated code, which can be used inside your VB application with some minor modifications.

Also, use "Option Explicit", don't use "As New" in declarations, and don't use default properties like "txtRow" - use "txtRow.Text".
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Expert Comment

by:weesiong
ID: 6947964
ryancys,

Try change this:
myWord.ActiveDocument.Shapes(1).AutoShapeType = wdHorizontalLineAlignRight

To:
myWord.ActiveDocument.Shapes(1).HorizontalLineFormat.Alignment = wdHorizontalLineAlignRight

From: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd10/html/woproAlignment.asp
0
 
LVL 54

Author Comment

by:Ryan Chong
ID: 6964703
Hi pals,

Sorry for the long delay, not working for a week already so don't get a chance to reply this question.

Now i was able to Align the picture like this:

Private Sub opt_Click(Index As Integer)
    Select Case Index
    Case 0
        myWord.ActiveDocument.Shapes(1).Left = 0
    Case 1
        myWord.ActiveDocument.Shapes(1).Left = (myWord.ActiveDocument.Tables(1).Cell(1, 1).Width - myWord.ActiveDocument.Shapes(1).Width) / 2
    Case 2
        myWord.ActiveDocument.Shapes(1).Left = myWord.ActiveDocument.Tables(1).Cell(1, 1).Width - myWord.ActiveDocument.Shapes(1).Width
    End Select
End Sub

But here is a problem, how can i add a picture on certain rows in a Table? I have tried but still can't get it yet!

* use this line to add rows on a table:
myWord.ActiveDocument.Tables(1).Rows.Add

Any suggestion or useful links on Word VBA? Thanks
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6964735
so nice wow, can relax 1 week
0
 
LVL 54

Author Comment

by:Ryan Chong
ID: 6964923
0
 
LVL 54

Author Comment

by:Ryan Chong
ID: 6967604
For ameba, thanks for provide me an alternative, but unfortunately i can't record for the picture editing part (Cannot change Picture Format when macro is recording), so i failed to solve the problem, until TimCottee solve the problem for me at this PAQ question:

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=20292962

So, can i PAQ this question for 0 points?

0
 
LVL 15

Expert Comment

by:ameba
ID: 6967872
That's good idea.  PAQ it!
0
 
LVL 54

Author Comment

by:Ryan Chong
ID: 6970512
Thanks :)
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 6970953
Points reduced and question put in PAQ


Thanks
COmputer101
E-E Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

886 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