Inserting 2 Images in a Single Cell - vba

I am new to VBA and request your assistance for the below query.
QUERY:
I want to insert two images, one below the other, in a Cell say B2 with already pre-configured enough Cell height and width.
I am using the below code
.Left = ActiveSheet.Range("B2").Left
.Top = ActiveSheet.Range("B2").Top
where in my 1st image is placed at the Top,Left of the Cell.Now how do i place the 2nd image in the same cell below the 1st image.
Is there any command like .Bottom?

There is no command like .Bottom, but an alternate approach for you could be simply adding the height of the first image to the top of the cell to decide where it ends. I.e.:
image2.Top = ActiveSheet.Range("B2").Top + image1.Height

Related

Powerpoint VBA - Autofit columns

I'm really a beginner at vba, but I've been puzzling around how to make it work. I'm creating a powerpoint presentation with Excel vba, based on data in an excel sheet a table is created on a slide in a newly created powerpoint presentation. I've got the table formatting done, which is a real hassle, by going over each individual cell and formatting them (looping, but still)....
The only thing missing is the individual column width. Based on the input data some columns might change in width,
Because of this reason I would like to have an autofit on the columns only. The rows should remain 1 line in height. But the column width should adapt to whatever would be necessary to keep the row height on 1 line.
Dim PPTtable1 As PowerPoint.Shape
With PPTtable1
.Left = 350
.Top = 150
.Width = 758
.table.Columns(1).Width = Auto
.table.Columns(2).Width = Auto
.table.Columns(3).Width = Auto
End With
This would turn the columns in the smallest possible width by stretching the height of the cells. Basically what I need is the function of double clicking on the side border of a column, and it will automatically fit to the correct width.
EDIT:
Maybe this would be interesting and important to know the order of the code:
Table is created
Format of the individual cells (bold, italic, size, font, etc...)
Data is filled in from an excel sheet
Trying to autosize the column

Adding a background image to a particular cell

I tried to insert the background image using following code:
Pic = "C://Picture/Logo1"
Activesheet.SetBackgroundPicture Pic
This inserts the picture to full sheet but I want to add it to particular cell or a range of cells. Please help
As far as I know excel doesn't support appending the image to a cell (with or without VBA).
The background of a single cell supports colors/gradients/fill-patters, but not the pictures.
It is possible however, to "place" the picture (shape) object with the same width and height right above the cell and make it locked and move around together with the cell if somebody attempts to resize cell widths. I personally wouldn't go that way, too much to code and too much risk of breaking the structure.

Excel Macro: Command buttons overlap the shape in worksheet

I have 2 command buttons, different height and width of the cells that need to be inserted every time and a fixed shape. Sometimes when the height and width are smaller, it tend to overlap with the command buttons. What should I do? I need the command buttons to be there. I tried to put certain range, it works but when the width and height of the cells gets bigger, it moves further away. Any idea? I'm thinking of maybe putting the range cells for the command buttons to stay as Range A and B as default. Will that work? But I don't know how to do it.
Set the top, left properties on the shape, then irrespective of the size it should always start at the same place.
Dim Fred as shape
Set Fred = activesheet.shapes.addshape(type,left,top etc,)
Fred.placement= xlfreefloating

table border thickness with UseVariableBorders set to true

I’m using iTextSharp 5.5.7 and PdfPTable.
I have a question about table border.
I need to customize the border (like the color or size for example). So I set UseVariableBorders to true.
In iText in action book, I saw that setting this method to true will make “the cell looks slightly bigger than the others : the thickness of the border is distributed equally inside and outside the cell dimensions”. This makes the outside border of the table looks smaller than the inside.
Other point, if you set for a cell, the border of the next cell will appear (in the example, the cell in the second column is merged vertically with a colspan of 2 and the last row cell is merged horizontally with a colspan of 2):
Is there a good way to avoid that? (table event?)

Write new entry into cell and autofit column width if it needs to become wider to fit the new entry?

I write a value into a cell:
Range("A1").Value = 13/3/2015
If the column is wide enough to accommodate that entry, I don't want it to change. If it is not wide enough, I want it to autofit. What is the best way of doing this?
The following should work
Range("A1").Value = 13/3/2015
Width = Range("A1").EntireColumn.ColumnWidth
Range("A1").EntireColumn.Autofit
if Range("A1").EntireColumn.ColumnWidth < Width then Range("A1").EntireColumn.ColumnWidth = Width
But I hope that there is a more clever way that does not require me to autofit the column width needlessly.
Autofit will adjust to the longest cell width in the column, provided wordwrap is no on. It will not change it if a larger width is not found. Your extra test is redundant.