|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Automatically adjust height of the row
I wqrote this macro, whcih inserts pictures into the excel worksheet and then it adjusts the height of the first row to the height of the picture. But the problem is that this macro only adjust the height of all the rows according to the height of the first inserted picture. What I want is I want each row to automatically adjust to the height if the picture that's placed in this row. Please, let me know what's wrong with my macro and I would also apreciate any suggestions on how to solve this problem. I greately apreciate it. Thank you.
here is the macro: Sub Macro1() Dim i As Integer Dim p As Integer Dim iHeight As Double Dim iDividor As Double Dim Counter As Boolean Dim sFilename As String Dim SamePicture As String Dim SamePicture2 As String Dim sFilename2 As String Dim bcontinue As Boolean Dim spath As String Dim iRest As Double iDividor = 5.25 iRest = 3.75 i = 1 SamePicture = njd3 bcontinue = True spath = "P:\Pictures\JPG\" Set oFSo = CreateObject("Scripting.FileSystemObject") While bcontinue sFilename = Worksheets(1).Cells(i, 3).Value sFilename2 = Worksheets(1).Cells(i, 2).Value iPos = InStr(1, sFilename, "-") If iPos <> 0 Then SamePicture2 = Mid(sFilename, 1, iPos) End If Counter = True 'worksheets is the number of the sheets, e.g. sheet1 = 1 sheet 2 = 2 etc. 'cells is the cell, the first parameter the row, the second the column If sFilename <> "" And sFilename2 <> "" Then Range(Cells(i, 1), Cells(i, 7)).Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone Selection.Borders(xlEdgeLeft).LineStyle = xlNone Selection.Borders(xlEdgeTop).LineStyle = xlNone With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With Selection.Borders(xlEdgeRight).LineStyle = xlNone Selection.Borders(xlInsideVertical).LineStyle = xlNone End If If sFilename = "END" Then bcontinue = False Else Range(Cells(i, 1), Cells(i + 2, 1)).Select 'select the cell where it should be inserted If sFilename <> "" And sFilename2 <> "" Then End If sFilename = spath + sFilename + ".jpg" If oFSo.fileExists(sFilename) And (SamePicture <> SamePicture2) Then ActiveSheet.Pictures.Insert(sFilename).Select 'inserts picture and select it iHeight = Worksheets(1).Shapes(1).Height Cells(i, 1).RowHeight = iHeight Counter = False sFilename = Worksheets(1).Cells(i, 3).Value iPos = InStr(1, sFilename, "-") If iPos <> 0 Then sFilename = Mid(sFilename, 1, iPos) SamePicture = sFilename End If 'Selection.ShapeRange.IncrementLeft 5 'Selection.ShapeRange.IncrementTop 12 End If i = i + 1 End If p = p + 1 Wend End Sub iHeight = Worksheets(1).Shapes(1).Height |
|
#2
|
|||
|
|||
|
This the property of the rowheight:
RowHeight Property Returns the height of all the rows in the range specified, measured in points. Returns Null if the rows in the specified range arent all the same height. Read/write Variant. Remarks For a single row, the value of the Height property is equal to the value of the RowHeight property. However, you can also use the Height property to return the total height of a range of cells. Other differences between RowHeight and Height include the following: Height is read-only. If you return the RowHeight property of several rows, you will either get the row height of each of the rows (if all the rows are the same height) or Null (if theyre different heights). If you return the Height property of several rows, you will get the total height of all the rows. i find it in the msdn wen site:http://msdn.microsoft.com/library/d...rorowheight.asp |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Automatically adjust height of the row |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|