Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27348

VS 2010 Sorting Excel sheets in alphabetical order

$
0
0
Hi guys,

Basically I'd like to arrange Excel sheets in alphabetical order using vb.net.
In this code:

vb.net Code:
  1. Dim xlApp As Object = CreateObject("Excel.Application")
  2.         Dim xlBook As Object = xlApp.Workbooks.Open(TextBox1.Text)
  3.  
  4.  
  5.         For i As Integer = 1 To xlBook.Worksheets.Count
  6.             If xlBook.Worksheets(i + 1).Name < xlBook.Worksheets(i).Name Then
  7.                 xlApp.Worksheets(i + 1).Move(Before:=xlBook.Worksheets(i))
  8.             End If
  9.         Next

I tried converting the code from the macro for sorting Excel sheets but this line:
vb.net Code:
  1. If xlBook.Worksheets(i + 1).Name < xlBook.Worksheets(i).Name

....is not the correct convention on comparing the alphabetical order of the sheets. What is the correct method? It seems that for the Office Interop, when I tried typing whatever the "inheritance" system spews out via IntelliSense didn't happen.

Thanks guys!
Vizier87

Viewing all articles
Browse latest Browse all 27348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>