Hello,
I got in trouble when I change the code to "for each loop" from "while loop"
because "while loop" gets all the pages sequentially. (and I don't know this also, to get each images in a single page)
I use this code, "for each loop" to get the imagecount in a single page of excel sheet.
Private function(byval pathfilename as string, byREF imagecount as integer, _
byREF pagecount as integer, byval selectPage as boolean, byval FILEpages as New List(of Integer)) as boolean
Dim ECel As New Excel.Application
ECel.Workbooks.Open(pathfilename)
Dim sheet As Excel.Worksheet = ECel.Sheets(1)
Dim r As Excel.Range = sheet.UsedRange
pagecount = sheet.PageSetup.Pages.Count ''The number of all pages in sheet (1)
imagecount = sheet.Shapes.Count ''The number of all images in sheet (1)
Dim sh As Single=0, sw As Single=0
Dim icount As Integer = 0, TotiCount As Integer = 0
IF selectPage = True Then
FILEpages.Sort()
pagecount = FILEpages.Count
For Each sheetPage As Integer In FILEpages ''STARTS getting a single page to count images.
If sheet.HPageBreaks(sheetPage).Location.Row <= r.Row Then ''i doubt this is incorrect, because theres no given pagebreak add
sheet.HPageBreaks(sheetPage).Location.Select() ''I think incorrect also...
icount = r.Rows.Worksheet.Shapes.Count ''incorrect also? It did not get the image in a single page, it counts all in a page.
For e As Integer = 1 To icount
sh += r.Worksheet.Shapes.Item(e).Height ''i doubt this is incorrect, because the range are the same usedrange
sw += r.Worksheet.Shapes.Item(e).Width ''i doubt this is incorrect, because the range are the same usedrange
Next
TotiCount += icount
End If
Next
imagecount = ToTiCount
ELSE
For e As Integer = 1 To imagecount ''There is no problem here, since it gets all the images in all pages of sheet (1)
sh += sheet.Shapes.Item(e).Height
sw += sheet.Shapes.Item(e).Width
Next
END IF
...
...more codes processes here...
...
Return True
End Function
I hope someone could correct the code, where did I go wrong, or its all wrong, or whats wrong in the lines.
Bookmarks