Hi, I'm trying to insert all the images in folder E:\Image to sheet "intrang", the first image will be placed at A1, then the next image will be placed in the next page, i have this code but it's have error Object required at this line If topPosition + .Height > Sheets("intrang").PageSetup.PrintArea.Height Then
I've check page setup, nothing seem odd
Please, help me fix this
I've check page setup, nothing seem odd
Please, help me fix this
Excel Formula:
Private Sub ToggleButton2_Click()
Dim folderPath As String
folderPath = "E:\Image"
Dim file As String
file = Dir(folderPath & "*.jpg")
Dim pic As Picture
Dim leftPosition As Double
Dim topPosition As Double
leftPosition = Sheets("intrang").Range("A1").Left
topPosition = Sheets("intrang").Range("A1").Top
Dim currentPage As Integer
currentPage = 1
Do While file <> ""
Set pic = Sheets("intrang").Pictures.Insert(folderPath & file)
With pic
If topPosition + .Height > Sheets("intrang").PageSetup.PrintArea.Height Then
currentPage = currentPage + 1 ' tang s? trang gi?y l?n
leftPosition = Sheets("intrang").Range("A1").Left
topPosition = Sheets("intrang").Range("A1").Top
End If
.Top = topPosition
.Left = leftPosition
topPosition = topPosition + .Height
If currentPage > Sheets("intrang").HPageBreaks.Count Then
Sheets("intrang").HPageBreaks.Add Before:=pic.Range
End If
End With
file = Dir
Loop
End Sub