Results 1 to 1 of 1

Jump to any page of excel sheet randomly, part2 (vb.net)

Threaded View

  1. #1
    Registered User
    Join Date
    06-16-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    9

    Post Jump to any page of excel sheet randomly, part2 (vb.net)

    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.
    Last edited by blaisexena; 06-19-2013 at 09:23 PM. Reason: edit code

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1