Solved

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

Posted on 2002-04-15
11
623 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 49

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
 
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 49

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
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.

 
LVL 7

Expert Comment

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

Author Comment

by:Ryan Chong
ID: 6964923
0
 
LVL 49

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 49

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

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

Suggested Solutions

Title # Comments Views Activity
Window placement 17 75
Access 2016 VB code 9 102
Visual Basic Excel Formatting error 4 83
using Access 8 58
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

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

24 Experts available now in Live!

Get 1:1 Help Now