• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1590
  • Last Modified:

Frame Height... VBA

   For i = 1 To ActiveDocument.Frames.Count
   
        ActiveDocument.Frames(i).Select
       
       ' need to add code here to reduce frame height down to 10, for example
       'but keeping the center from top of the page unchanged.

        ' Also what is the code to read frame height?
        'MsgBox Selection.Borders.Height  '<-- doesn't work

    Next i

Question1: How to reduce frame height to a specified value keeping left to right center line of the frame on the same place.

Question2: What is the syntax to read the height of a frame?

Thank you.
0
Mike Eghtebas
Asked:
Mike Eghtebas
  • 11
  • 7
  • 2
1 Solution
 
geneusCommented:
Question #2

Sub FrameInfo()

varHeight = PointsToInches(ActiveDocument.Frames(1).Height)
varWidth = PointsToInches(ActiveDocument.Frames(1).Width)
MsgBox "Height is " & varHeight & " inches"
MsgBox "Width is " & varWidth & " inches"

End Sub
0
 
zorvek (Kevin Jones)ConsultantCommented:
Question #1:

ActiveDocument.Frames(1).Top = ActiveDocument.Frames(1).Top + (ActiveDocument.Frames(1).Height - 10) / 2
ActiveDocument.Frames(1).Height = 10

Kevin
0
 
geneusCommented:
Question #1

Sub FrameHeightnTwo()

varHeight = PointsToInches(ActiveDocument.Frames(1).Height)
varNewHeight = ActiveDocument.Frames(1).Height / 2
ActiveDocument.Frames(1).LockAnchor = True
ActiveDocument.Frames(1).Height = varNewHeight

End Sub
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
geneusCommented:
Just Lock the Anchor ; )
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you for the good responses.

Testing PointsToInches(ActiveDocument.Frames(1).Height) on a frame gives me -1.38 E-02, and  ActiveDocument.Frames(1).Height gives me -1

How this is possble? What am I doing wrong? I was expecting a possitive value.

After ironing out this part I will test the solution from Kevin.

Mike
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Checking the propery of the frames, I have frame height on Auto with blank "At" box.

Using:    ActiveDocument.Frames(i).Height = 10,

Auto changes to "At Least" with "At" = 1.4

So, in order for them all to have the same height, I will apply

ActiveDocument.Frames(i).LockAnchor = True
ActiveDocument.Frames(i).Height = 10

What do you think?

Mike
0
 
zorvek (Kevin Jones)ConsultantCommented:
>How to reduce frame height to a specified value keeping left to right center line of the frame on the same place.
I think I misunderstood your request. What do you mean by "center line"? In the same place relative to what?

Kevin
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Kevin,

My apology for the poor description.
                         
   |----------------------------------
   |                                          |
------- - -------- - ----------- - ----------  <-- left to right center line of the frame
   |                                          |  
   |_____________________|  
       ^--- frame
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
geneus,

It seems the following line is anchoring the top-left corner not left-center point.

ActiveDocument.Frames(i).LockAnchor = True

     /---  top-left corner
   x----------------------------------
   | /--- left-center point          |
--x---- - -------- - ----------- - ----------  
   |                                          |  
   |_____________________|  
       ^--- frame
0
 
geneusCommented:
Sub FrameX()
'

varHeight = PointsToInches(ActiveDocument.Frames(1).Height)
varNewHeight = ActiveDocument.Frames(1).Height / 2
varVertPos = ActiveDocument.Frames(1).VerticalPosition
varNewVertPos = varVertPos + varNewHeight
ActiveDocument.Frames(1).LockAnchor = True
ActiveDocument.Frames(1).Height = varNewHeight
ActiveDocument.Frames(1).VerticalPosition = varNewVertPos


End Sub
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
geneus,

I have old frame and want to change it to new frame.

   ----------------------------
   |                                  |                   |--------------------------|
--x---- - -------- - --------------             --x---- - -------- - --------------            
   |                                  |                   |________________|
   |_________________|                       ^--- new frame
       ^--- old frame                                     - height = 10
           - any height                                    - center line the
                                                                     same as olf frame
 
I am having some problems with your last post. Now, I am preparing some notes to post it here.

Thanks,

Mike
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
I ran this code (the same as yours). I have uploaded the properties snapshot of both old and new frames for you to view if necessary.

In these codes I have included some comment and numbers for your information:

======= Your Code ============

' find the height of the frame as it is. (reads varHeight = -1.388889E-02)
varHeight = PointsToInches(ActiveDocument.Frames(intFrmCount).Height)

' determine new half-height for the frame (Note: I wanted it to be 10)
' or varNewHeight = 10/2  ' or just 5
' (reads varNewHeight = -0.5)
varNewHeight = ActiveDocument.Frames(intFrmCount).Height / 2

' find the top position of the frame as it is.  (reads varVertPos = 624.9)
varVertPos = ActiveDocument.Frames(intFrmCount).VerticalPosition

' determine the new top position of the frame
' v-- isn't this relative position of the bottom of the frame?
' (reads varNewVertPos = 624.4)
varNewVertPos = varVertPos + varNewHeight

' anchor the frame (does this mean keep the dimensions
' fixed or anchor it at top-left position for example?)
ActiveDocument.Frames(intFrmCount).LockAnchor = True

' new height is expected to be 10. Could we just write
' ActiveDocument.Frames(1).Height = 10
ActiveDocument.Frames(intFrmCount).Height = varNewHeight

' shift the frame to its new position
ActiveDocument.Frames(intFrmCount).VerticalPosition = varNewVertPos
======= End of the Code ============

I will post the link for the snapshots shortly.

Thank you,

Mike
0
 
geneusCommented:
I misunderstood originally.  I thought you wanted the Center line to be the top.  I modified the code you just posted.  You stated that you wanted the Height to be 10 but I was unsure of what unit of measure you wanted to use.  All calculations are based on points.  In my original example I converted the points to inches so that you could see the result.

------------------------------------------------------------------------------------------------------------------------
Sub YourCode()
' find the height of the frame as it is. (reads varHeight = -1.388889E-02)
'Removed PointsToInches as all sizes are calculated in Points this was to demonstrate it in inches
varHeight = ActiveDocument.Frames(1).Height

' determine new half-height for the frame (Note: I wanted it to be 10)
' or varNewHeight = 10/2  ' or just 5
' (reads varNewHeight = -0.5)

varNewHeight = 10 'Set to 10 as specified.   Now if you want this to be 10 inches, change it to
'InchesToPoints (10)
'Removed => ActiveDocument.Frames(1).Height / 2

'Calculate your change in Height
varChangeInHeight = varHeight - varNewHeight

'Calculate the Vertical Shift
varVertShift = varChangeInHeight / 2


'-----This Section may not be necessary--------------------
'Relative Vertical Position
    varRelVPos = ActiveDocument.Frames(1).RelativeVerticalPosition
    If varRelVPos = 0 Then
    varRelVPosSet = wdRelativeVerticalPositionParagraph
    ElseIf varRelVPos = 1 Then
    varRelVPosSet = wdRelativeVerticalPositionPage
    ElseIf varRelVPos = 2 Then
    varRelVPosSet = wdRelativeVerticalPositionParagraph
    End If
'----------------------------------------------------------

' find the top position of the frame as it is.  (reads varVertPos = 624.9)
varVertPos = ActiveDocument.Frames(1).VerticalPosition

' determine the new top position of the frame
' v-- isn't this relative position of the bottom of the frame?
' (reads varNewVertPos = 624.4)
varNewVertPos = varVertPos + varVertShift 'varNewHeight

' anchor the frame (does this mean keep the dimensions
' fixed or anchor it at top-left position for example?)
ActiveDocument.Frames(1).LockAnchor = True

' new height is expected to be 10. Could we just write
' ActiveDocument.Frames(1).Height = 10
ActiveDocument.Frames(1).Height = varNewHeight

' shift the frame to its new position
ActiveDocument.Frames(1).VerticalPosition = varNewVertPos

'Set Relative Vertical Position <-If Other section is omitted then take this out too
ActiveDocument.Frames(1).RelativeVerticalPosition = varRelVPosSet


End Sub
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Hi geneus,

Thank you so much for the great code. I has solved most of the problems except one. In the link below, I have included two PNG images with some explanations on them:

https://filedb.experts-exchange.com/incoming/ee-stuff/216-blank.txthttps://filedb.experts-exchange.com/incoming/ee-stuff/4905-FrameProperties.PNG
https://filedb.experts-exchange.com/incoming/ee-stuff/4906-Frames.PNG
https://filedb.experts-exchange.com/incoming/ee-stuff/4909-FrameProperties2.PNG


There is a frame where some codes runs to edit its text content a bit-- removes some chr(13) from the text string inside the frame. After runing this edit plus your code, it doesn't remain at the same location. It moves up.

The text in the other frames are also edited (this is not the only one) but at the end this particular frame moves up considerably while the other frame remain in their oroginal locations. I hope the images tell it all.

Thanks again.

Mike
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
BTW, I have made the images yesterday with the old solution. The difference with the new solution is the final frame-heights are all 10 but the frame with text moves upward. Now, I will make new images base on your new solution and resubmit them for your review.

Thanks,

Mike
0
 
geneusCommented:
It sounds like your Center Line is shifting for the Frames due to the extra spaces being removed and the Height/Width Being Set to Auto.  Set your Height to Fixed.

'Change the Height from Auto to Fixed
If ActiveDocument.Frames(1).HeightRule = 0 Then
    varVPos = ActiveDocument.Frames(1).VerticalPosition
    varLineCount = ActiveDocument.Frames(1).Range.ComputeStatistics(Statistic:=wdStatisticLines)
    varFontSize = Selection.Font.Size
    varCalcHeight = 1.2 * varLineCount * varFontSize
    ActiveDocument.Frames(1).HeightRule = wdFrameExact
    ActiveDocument.Frames(1).Height = varCalcHeight
    ActiveDocument.Frames(1).VerticalPosition = varVPos
End If
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Please see the image based on the last solution at:

https://filedb.experts-exchange.com/incoming/ee-stuff/4909-FrameProperties2.PNG 

Mike
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
re: > Set your Height to Fixed.

This a document with many frams and it is not practical for me to set them to fixed manually. I will close this question now and post a new question asking for solution to set these properties to fixed etc.

Thank you for the great solutions.

Regards,

Mike
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
geneus,

If you have the time, I have an easy one at:

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_22870338.html

Of course, easy one for you.

BTW, there was some errors in my excution of the code. I will update you shortly.

Thanks,

Mike
0
 
geneusCommented:
Sub FrameHeightSet()
'Sets the height to an exact number on all frames in document
For h = 1 To ActiveDocument.Frames.Count
'Change the Height from Auto to Fixed
    If ActiveDocument.Frames(h).HeightRule = 0 Then
        varVPos = ActiveDocument.Frames(h).VerticalPosition
        varLineCount = ActiveDocument.Frames(h).Range.ComputeStatistics(Statistic:=wdStatisticLines)
        varFontSize = Selection.Font.Size
        varCalcHeight = 1.2 * varLineCount * varFontSize
        ActiveDocument.Frames(h).HeightRule = wdFrameExact
        ActiveDocument.Frames(h).Height = varCalcHeight
        ActiveDocument.Frames(h).VerticalPosition = varVPos
    End If
Next h

End Sub
0

Featured Post

Technology Partners: 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!

  • 11
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now