VBA resize table to fit to page's width - vba

I want to resize a table to fit to the pages width via VBA code.
I have tried it with the following code:
mytable.PreferredWidthType = wdPreferredWidthPercent
mytable.PreferredWidth = 100
Can anyone tell me how I can resize the table to the page size? My first page has an edge of 2 centimeters and because of this the table jumps to page 2.
Thanks in advance!

You could try the AutoFitBehavior property of the table.
mytable.AutoFitBehavior = wdAutoFitWindow
AutoFitBehavior

Related

problem with fitting datagridview height according to the content

I have a datagridview whose styling is kept as follows
dgvCreatinine.AutoGenerateColumns = False
dgvCreatinine.AutoSize = False
dgvCreatinine.AutoResizeRows()
dgvCreatinine.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill
dgvCreatinine.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders)
dgvCreatinine.DataSource = dtTemp
It is appearing as shown in the attached image
As you can see the gridview is not resizing to the content along row wise. Could someone tell me how this can be accomplished? Thanks in advance.
You can just set the height of the entire control using this formula
DataGridViewHeight = HeaderHeight + NumberOfRows * RowHeight
Code:
dgvCreatinine.Height =
dgvCreatinine.ColumnHeadersHeight _
+ dgvCreatinine.Rows.OfType(Of DataGridViewRow).First().Height * dgvCreatinine.Rows.Count()
This works, but could use some tweaking. For example, there may be a better way to get the row height. And you may also need to add a pixel or two depending on borders. Also, if you have an underlying DataSource, you could get the rows count from it.
That code should be called whenever a row is added or removed, or DataBindings are updated etc.

Inserting images automatically on slides referencing model #? MICROSOFT POWERPOINT

I have about 100 slides here on powerpoint that look like this:
Slide example screenshot
I need to insert an image into the text box on each slide with the sizing of
height = 5, width = 3.64
and positioning of:
Horizontal = 6" / Vertical = 1.2" (Both from top left corner)
For good measure, here are all of the image format settings:
Image format settings screenshot
The image files are the same as the model number, such as MHS1306.jpg.
Is there any way to use a macro to automatically reference the model number, insert the corresponding image, and then resize it to the correct size?
All of the images are in the same folder.
The image just needs to be in that position, the text box isn't important, just shows where the image should go.
I am very new to VBA and scripts, and basically know nothing about it yet, so I would appreciate any help.
Thanks.

Scrollable image in userform

I have a word doc with a bunch of ActiveX Control buttons or whatever on it, and each time a button is clicked, a corresponding image needs to be displayed in a popup box.
I have a userform called ImageForm, and this is what I'm doing right now:
Sub Button_Clicked()
ImageForm.Picture = LoadPicture("appropriate_image_path")
ImageForm.Show
End Sub
Each of these images has a width of 8.5 inches, but their heights can vary anywhere from like 3 to 20 inches (they're snippets of a pdf). So I've set the width of the userform to a little more than 8.5 inches, and that looks fine. But I need to be able to scroll vertically through the image in the userform, since some of the images could be taller than a user's monitor.
I'm completely stuck on this. What I've tried so far is adding a frame to the form, then adding an image control inside the form, and setting the "ScrollBars" property of the frame to vertical. Then instead of using "ImageForm.Picture = ..." I use "ImageForm.ImageControl.Picture = ..." But it doesn't work.
Any insight here would be greatly appreciated. Hopefully this question is clear enough, I've only been using VBA for a month or so now. (I miss Java so, so much)
Thanks!
Here is a neat little trick based on one of my posts
The idea is to ensure that the image control is in frame control and the image control doesn't have a border. Also the image control's PictureSizeMode is set to fmPictureSizeModeClip so that we can scroll the image
SNAPSHOT (DESIGN TIME)
SNAPSHOT (RUN TIME)
CODE
Private Sub UserForm_Initialize()
With Frame1
'~~> This will create a vertical scrollbar
.ScrollBars = fmScrollBarsVertical
'~~> Change the values of 2 as Per your requirements
.ScrollHeight = .InsideHeight * 2
.ScrollWidth = .InsideWidth * 9
End With
With Image1
.Picture = LoadPicture("C:\Users\Public\Pictures\Sample Pictures\Desert.jpg")
.BorderStyle = fmBorderStyleNone
.PictureSizeMode = fmPictureSizeModeClip
End With
End Sub

Fix radgrid height with paging

How to fix the size of radgrid irrespective of records.
I set the paging with pagesize = 5.
When radgrid has 5 rows its height will be ok.
If the grid has 2 rows its fits to the 2 rows height.
How to fix the radgrid height.
I think you got my problem.
I'm doing like this in page_load
radgrid.Height=Unit.Pixel(200);
Hi can anyone answer my question..?
In the Databound() event handler, check for the number of records.
int c = RadGrid1.Items.Count()
Then try your:
RadGrid1.Height = Unit.Pixel( Whatever you want ) * c;
set the scroll height instead of setting the height. This makes sure that the whole data area height is maintained.
RadGrid1.ClientSettings.Scrolling.ScrollHeight = Unit.Pixel(200);
This article may help as well.
http://www.telerik.com/help/aspnet-ajax/grid-height-vs-scrollheight.html

The control or subform control is too large for this location on resize

I have a simple form in Access 2003. The form has a List control and a button. I wanted to make the list to resize with the form (only vertically) while the button remains at the bottom right of the List. I'm using the following code on the form's resize event.
list.Height = Me.InsideHeight - list.Top - 200
commandButton.Top = list.Height + list.Top + 50
This works fine as I resize the form, until the form height gets to a certain height. Then I get this error;
Run-time error '2100':
The control or subform control is too large for this location
This error is occurring at the line where I'm assigning the commandButton.Top. If I remove this line then the list height changes fine. I don't have any subforms in the form.
Does anyone know why this is happening?
Thanks
I think it is because you need to resize the detail section of the form first.
Try changing the code to
Me.Section(0).Height = Me.InsideHeight
list.Height = Me.InsideHeight - list.Top - 200
commandButton.Top = list.Height + list.Top + 50
Came by here (as many have) with the same problem and then realised my issue. Be mindful when resizing a control to a larger size with regard to the order of setting properties.
I would recommend setting the TOP and LEFT positions before HEIGHT and WIDTH.
Although my final sized control should have fitted OK once resized, I had originally tried setting the WIDTH first which attempted to enlarge the control exceeding the width of the form. My application threw the 2100 error at that point. I really hope this helps someone! Also, don't forget to set dimensions in TWIPS which is set as INCHESS x 1440 (or CM x 566.9291), ie: .Width = 10 * 566.9291 to set a control width to 10cm.
I get this same error if I set the width to greater the 31680.
With a little more research, I notice MS Access only allows a form width to be 22" wide. 22" = 31680 TWIPS.
So my workaround solutions it to add a check:
If newWidth > 31680 Then newWidth = 31680