i want to know if what is the thing that calculate when i call "object.LEFT" in visual basic express 2010, same thing as right bottom and .top..
thankz in advance! ^^
object.left is a property of a control that specifies its relative distance (in pixels) from the control's parent container.
For example: if you have object.left set to 50, then it will push the control in 50 pixels from the left side of the container (i.e. a Form in WinForms development or Page in ASP.NET development).
Yes, I could be more specific if you provided more specific detail about the specific object, and what your purpose was.
In VB there are .Left, .Top, .Width and .Height properties that are usually measured in screen pixels to define the position and size of a Control (ListBox, CheckBox, TextBox, etc) on a Form. Footnote: VBForms can be set to use twips, points, centimeters and inches as their basic measurement.
In Office (Word, PowerPoint, Excel) there are controls that are similar but NOT the same exactly as those in VB UI. They can be placed on a UserForm using these same properties. To place them on a Word document however, you need the .GetPoint method that allows you to specify a .Range object on your document and this function will fill-in the placement information
myWorkingDoc.Windows.Item(1).GetPoint ScPixLeft, ScPixTop, ScPixWidth, ScPixHeight, _
TblControl.Rows.Item(4).Cells.Item(1).Range.OMaths.Item(1).Range
The above line defines 4 Long integers: ScPixLeft, ScPixTop, ScPixWidth, ScPixHeight and a Range object in a word document, in the above case a Word Table named TblControl, the 4th row, 2nd (cell) column. WIthin a Word document window object the .GetPoint method gives one the relative placement, in pixels, within the document window. I use ScPixWidth and ScPixHeight to give me the size of the math equation (OMath object) so I can size an InlineShape to contain it.
Related
I have a graphics as per the below snap, where i want to make Bold to the 1st item and last item should be italic. So to achieve this i think i have to loop though the each item of the certain graphics in Visio.
So i have tried the the below VBA code, but it only displays the graphics item ID and name.
For intCounter = 1 To ActiveDocument.Masters.Count
If ActiveDocument.Masters(intCounter).Type = visTypeDataGraphic Then
Debug.Print ActiveDocument.Masters(intCounter).Name, ActiveDocument.Masters(intCounter).ID
End If
Next
So I need the detail process to loop through the graphics item for each element so that my findings can be handled ?
I have several data graphics entities in a page and I want data graphic item should be changed all such entities at once. I don't find any option in "Edit Data Graphic" to change its item wise properties like 'Bold', 'Italic' etc.
When you link External data with your document Visio engine automatically add few hidden build-in master shapes to Document stencil.
You can find these changes via Drawing Explorer window.
Each master shape contain some sub-shapes into.
You must iterate these sub-shapes!!!
i'am currently trying to add a small function to PowerPoint using VBA, my goal is to create a gadget that works kind of like Photoshop graphics layer.
My plan is to add a layer name Tag on each shape that is drawn by user, so later I can parse through every item by loop and preform lock/unlock, show/hide shapes based on it's tag value, such as:
Sub add_shape_with_layer_tag()
Set islide = ActivePresentation.Slides(1)
Set ishape = islide.Shapes.AddShape(msoShapeRectangle, 5, 5, 80, 60)
ishape.Tags.Add "Layer", "1"
End Sub
Sub show_hide_layer_one_shapes()
Dim active_slide As Slide
Set active_slide = ActiveWindow.View.Slide
For Each ishape In active_slide.Shapes
If ishape.Tags("Layer") = "1" Then
ishape.Visible = Not (ishape.Visible)
End If
Next ishape
End Sub
However, I couldn't found a way to achieve this, so I would like to ask whether there's a method that provides following functions?
override add shape function so I can sneak tag value in to shape every time user drawn a shape
catch add shape event (if this thing did exist) so i can add tag to the last added item
a way to set a default tag value to shape, just like setting default shape color/line width
or is there any better options that is also viable?
thanks.
20200728
To John, thanks for the advice, I did found some interesting event that might be helpful for some of my other projects, however I couldn't found events that able to trigger after custom function while shape is added.
To Steve, my plan is to add a modeless userform with list UI that manage layers, the shape tag and shape fill texture/color will be determined based on what list item that currently selected.
As to saving settings, I'll use VBComponents.CodeModule to dump existing settings in userforms to a VBA module and store as text, so in theory I should able to make this function self contained in one file.
Not totally an answer, sorry SO, but comments don't allow enough scope for this. So ...
To Steve, my plan is to add a modeless userform with list UI that manage layers, the shape tag and shape fill texture/color will be determined based on what list item that currently selected.
Ah, so you're creating your own "pseudo-layers". That wasn't clear. Thanks for the add'l info. As it happens, I have a selection manager add-in that works very similarly to what you're proposing.
To John, thanks for the advice, I did found some interesting event that might be helpful for some of my other projects, however I couldn't found events that able to trigger after custom function while shape is added.
The SelectionChange event should get you there. When it fires, you'll need to check first to see if the current selection is a shape or something else. If a shape, check to see if its .Index = current slide's .Shapes.Count and also to see if you've already tagged it. If no tag AND if it's the correct index, it'll be a newly added shape. If you're tagging ALL shapes, you may only need to check to see if the .Tag(name) is blank.
As to saving settings, I'll use VBComponents.CodeModule to dump existing settings in userforms to a VBA module and store as text, so in theory I should able to make this function self contained in one file.
Why not save any needed slide or presentation level info as further slide- or presentation-level tags? PPT can absorb quite a lot of info as tags w/o getting cranky.
How can I get an Excel Form Control Label which is on a worksheet to change it's length to match the length of the sting of characters in it's caption. Importantly it must work irrispective of what screen the file is viewed on or what the zoom setting is on the sheet.
So far I've got:
Sub LabelLength()
Dim XYLabel As Shape
Dim XYDataSheet As Worksheet
Set XYDataSheet = ThisWorkbook.Sheets(1)
Set XYLabel = XYDataSheet.Shapes(1) 'This is the Forms Label
XYLabel.OLEFormat.Object.Caption = Trim(XYDataSheet.Cells(1, 1).Value)
XYLabel.Width = Len(Trim(XYDataSheet.Cells(1, 1).Value)) * 7.5
End Sub
Which works, but does leave quite a lot of space after some captions.
I don't think this can be done with a Form control, at least not directly. If you want to stick with a Form control, I think you're on the right track with scaling its .width property based on the text size. To do it better than that, you'd probably have to build a dictionary object or something and sum the width of all characters in the string based on the width you had listed in the dictionary object.
However, if you can switch your label to an ActiveX control, then you can solve this by using:
.WordWrap = False
.AutoSize = True
I think people in general prefer to use Form controls because they're a bit more simple. But I also think, in general, ActiveX controls have more flexibility and you can customize them to your needs more. You can read a bit more on Form controls vs. ActiveX controls here.
I want to use a word macro to set the position of the shapes in the document to book layout (see screenshot). But I can't find any reference which member I need to set for this (probably because my word is in german and this is called differently in the macro).
Can anyone tell me how to set the horizontal layout of a shape to book layout in vba?
[update] The following did the trick:
Shape.Left = -999994
Shape.LeftRelative = -999999
Shape.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
In the most recent versions of Word the macro recorder gives no help for graphical objects. The next best thing you can do is to look at the properties available for the object in the Object Browser (F2).
If a graphical object has "text wrap" formatting then it belongs to the Shapes collection, so the list you need to look up is that of the Shape object.
In there you'll find the property RelativeHorizontalPosition, which takes a member of the WdRelativeHorizontalPosition enumeration. Looking at that list there are a number of options, none of which has "book" in it.
So the next step is to insert and format a Shape with the desired positioning. Then in the Immediate Window (Ctrl+G) you can type:
?ActiveDocument.Shapes(1).RelativeHorizontalPosition
Then press Enter. This will print a number that corresponds to the list of Enumeration members.
You can also test the effect of the various members by assigning them in the Immediate Window:
ActiveDocument.Shapes(1).RelativeHorizontalPosition = wdRelativeHorizontalPositionOuterMarginArea
Press Enter.
What you'll see is that there is not an enumeration member for every option in the dialog box. And that various positioning options in the dialog box correspond to a single enumeration member.
For your specific question, wdRelativeHorizontalPositionInnerMarginArea corresponds to the dialog box option you indicate.
ActiveDocument.Shapes(1).RelativeHorizontalPosition = wdRelativeHorizontalPositionInnerMarginArea
Besides the above, you need to use the LeftRelative and Left properties, as well. Take a look at those settings in the Immediate Window after using the dialog box and play with them, putting the image on odd/even pages.If it disappears - it's off visible portion of the page, which you can see in Reading View. In a nutshell, you need the NEGATIVE numbers to lock the image to the margin or page side. Positive numbers position it absolutely.
I have a set of linked subs which work like this:
A user types into an ActiveX TextBox
A Change Event in that TextBox calls a sub in a Module
That Module sub drives updating a named range in a sheet
The range value drives updating a table of Excel cells that uses lookup functions based on the range value
The table values are copied and pasted to a another range (to eliminate links to formulas)
That pasted range is put into a ListBox using this (props to Rory for his patience):
ActiveSheet.ListBox1.List = Sheets("Search Criteria Control").Range("G1:G21").Value
The result is that for every character the user types in the TextBox the ListBox is updated.
The problem I have is that the ListBox shrinks a bit with every keystroke in the TextBox referred to in #1 above. Is this normal behavior and I'm misusing ListBoxes, am I doing something wrong or do I need to respecify the dimensions of the ListBox every time it is updated with something like this?
ActiveSheet.OLEObjects("ListBox1").Top = 35
ActiveSheet.OLEObjects("ListBox1").Left = 650
ActiveSheet.OLEObjects("ListBox1").Width = 550
ActiveSheet.OLEObjects("ListBox1").Height = 610
Thanks in advance for any thoughts on this.
I was having trouble with the same thing. My ActiveX listbox would move around on the sheet and change size for no reason that I could see.
While I did go ahead and develop some code to reset size and coordinates, that wasn't satisfactory since there had to be a mechanism to trigger that code - something I didn't want to burden end-users with.
I found a better answer in another user forum. There's a Listbox Property called IntegralHeight whose default property is True - something to do with screen resolution and optimal display of listbox contents. Simply set that to False. I did that with some ActiveX boxes that were giving me fits, and I was able to disable the "adjustment" code and, so far, so good!