Results 1 to 6 of 6
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how do you obtain a shape objects position?

    Hiya -
    VBA - Word97 sr2

    I have code which inserts objects & textboxes into a document - at certain locations ie horizontal positions.

    I'm working on code to remove objects & textboxes.
    To remove the object - I want to obtain to the current objects horizontal position & test.
    If the test is true then delete object.

    Does anyone know how to return position values for object shapes?
    as my attempt to obtain left value is not the correct measurement.

    please find code below so you can get an idea of what I'm attempting.
    Thanks in advance - Diana


    Dim x As Integer
    Dim i As Integer
    Dim y As Double

    Dim arrFormatCorrsLogo(7) As String
    Dim arrFormatSchneiderLogo(7) As String
    Dim arrayFormatAddress(7) As String


    'store array items for formatting of corrs logo object
    arrFormatCorrsLogo(1) = "-0.6"
    arrFormatCorrsLogo(2) = "2.33"
    arrFormatCorrsLogo(3) = "5.32"
    arrFormatCorrsLogo(4) = "8.4"
    arrFormatCorrsLogo(5) = "11.35"
    arrFormatCorrsLogo(6) = "14.26"
    arrFormatCorrsLogo(7) = "17.2"

    'store array items for formatting of schneider logo object
    arrFormatSchneiderLogo(1) = "-0.04"
    arrFormatSchneiderLogo(2) = "2.73"
    arrFormatSchneiderLogo(3) = "5.81"
    arrFormatSchneiderLogo(4) = "8.81"
    arrFormatSchneiderLogo(5) = "11.77"
    arrFormatSchneiderLogo(6) = "14.88"
    arrFormatSchneiderLogo(7) = "17.74"

    'store array items for formatting of company address
    arrayFormatAddress(1) = "-0.34"
    arrayFormatAddress(2) = "2.59"
    arrayFormatAddress(3) = "5.58"
    arrayFormatAddress(4) = "8.64"
    arrayFormatAddress(5) = "11.59"
    arrayFormatAddress(6) = "14.63"
    arrayFormatAddress(7) = "17.38"


    'obtain position of cursor in table
    If Selection.Information(wdWithInTable) Then
    x = Selection.Information(wdStartOfRangeColumnNumber)
    Else
    ActiveDocument.Tables(1).Columns(1).Select
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    x = Selection.Information(wdStartOfRangeColumnNumber)
    End If

    frmSmallSpines.Hide 'dd - remove after testing completed



    If chkRemoveCompanyLogo = True Then

    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.HomeKey Unit:=wdLine

    i = Selection.Range.Sections(1).Footers(wdHeaderFooter FirstPage).Shapes.Count

    strPostionLogoCorrs = arrFormatCorrsLogo(x)
    strPostionLogoSchneider = arrFormatSchneiderLogo(x)
    strPostionAddress = arrayFormatAddress(x)



    For k = 1 To i

    Selection.Range.Sections(1).Footers(wdHeaderFooter FirstPage).Shapes(k).Select

    y = Selection.ShapeRange.RelativeHorizontalPosition

    If (y = strPostionLogoCorrs) Or (y = strPostionLogoSchneider) Then

    Selection.Range.Sections(1).Footers(wdHeaderFooter FirstPage).Shapes(k).Select
    Selection.Range.Sections(1).Footers(wdHeaderFooter FirstPage).Shapes(k).Delete
    End If
    Next

    'goto main doc
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    End If

    'if checkbox Add company name is selected or Corrs logo is selected or schneider logo selected -
    'then format company logo & address
    If (chkAddCompanyLogo = True) Or (optCorrs.Value = True) Or (optSchneider.Value = True) Then

    ' code to insert & format company logos & address
    Endif

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: how do you obtain a shape objects position?

    Hi Diana,

    The attempts I've made to work with those properties have me convinced that trying to work with them via code is very snarky.

    Here's a workaround that might avoid having to deal with the Shape position issue altogether - would this work in your situation?:

    Assuming what you've got in the textboxes are logos, and you want to delete the textboxes based on which logo it contains - before inserting the logo into the textbox, type a text identifier into the textbox. Then when you insert the logo it should cover up the text identifier. You could then return the value of the text identifier via something like:

    If ActiveDocument.Shapes(1).TextFrame.TextRange.Text = "Schneider" Then
    ActiveDocument.Shapes(1).Delete
    End If

    Gary

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do you obtain a shape objects position?

    HI Gary

    Please find sample text document.
    I could also attach template if that would help - just let me know.

    I previously had bookmarked the logos so I could goto position of bookmarks & select object & delete.
    When I bookmarked the textboxes - the bookmark wouldnt go around the textbox - but inserted the bookmark inside the texbox. (see sample attached doc)

    however when I coded for this logic I still had problems selecting the correct object to do a test for existing bookmark - so I canned that idea.

    Diana
    Attached Files Attached Files

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: how do you obtain a shape objects position?

    Diana,

    What about putting a borderless table in the header? - size the cells as you need 'em, put the logos in the cells and bookmark them that way - that way you can just use the standard methods for getting at bookmarks, without needing to figure out which object you need to get to.

    Gary

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do you obtain a shape objects position?

    Hi Gary

    Your've just given me an idea.
    For the footer company address details
    instead of having floating textboxes for each cell>
    I will have 1 floating textbox & format & insert 1 table (by 6 columns/cells) to insert & delete company address details.
    this works.

    For the header logos I'm still working on.
    Do you know if there's a way to name objects
    like bookmarking, but naming objects so I can go to object name instead of the bookmark?

    Diana

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how do you obtain a shape objects position?

    HI Gary

    I've worked out how to delete the logos in header.

    when shape logos are inserted they are given a name
    Selection.ShapeRange.Name = "Logo" & x

    When shape logo is to be removed I've used the following code which works:
    Dim shpShape As Shape
    strLogo = "Logo" & x

    'obtaint total count of objects
    i = Selection.Range.Sections(1).Headers(wdHeaderFooter FirstPage).Shapes.Count

    'remove company logo in header
    For k = 1 To i

    Selection.Range.Sections(1).Headers(wdHeaderFooter FirstPage).Shapes(k).Select
    Set shpShape = Selection.Range.Sections(1).Headers(wdHeaderFooter FirstPage).Shapes(k)

    If shpShape.Name = strLogo Then
    Selection.Delete
    Exit For
    End If
    Next

    & for the footers with company address details
    I've created a floating textbox & inserted 1 table by 6 columns.
    Just goto column & delete text.

    Beautiful - thanks for all your help!
    Diana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •