RyanG-7680 avatar image
0 Votes"
RyanG-7680 asked ·

VB .net accessing excel files offline

I'm writing a program that creates and reads excel spreadsheets. They are stored in My Documents so that they're synced with OneDrive.
Everything in my OneDrive is set to be available offline.
When I disconnect from wifi, I get an error saying "Network not detected" in Visual Studio, however, Excel will open then while offline when I click on them in File Explorer. Note: there are text files in the same OneDrive folder that this program opens and writes to with no problem when offline.

  Public Function CurrentYearPath() As String
             Dim CurrentYear As Integer
             CurrentYear = CInt(Format(Now, "yyyy"))
             Return My.Computer.FileSystem.SpecialDirectories.MyDocuments + "\DailyBook\Rosters\Membership" + CurrentYear.ToString + ".xlsx"
   End Function

 Public Sub LoadMemberList()
         Dim mMember As Members
         Dim xlApp As Excel.Application
         Dim xlBook As Excel.Workbook
         Dim xlSheet As Excel.Worksheet
         Dim range As Excel.Range
         xlApp = New Excel.Application
         xlBook = xlApp.Workbooks.Open(CurrentYearPath)
         xlSheet = xlBook.Worksheets("sheet1")
         range = xlSheet.UsedRange
         Dim rs As Object(,) = CType(range.Value, Object(,))
         Dim records As Long = rs.GetUpperBound(0)
         If records > 1 Then
             For x = 2 To records
                 mMember.MemberNumber = FormatNumber(rs(x, 1))
                 mMember.MemberName = rs(x, 4) + " " + rs(x, 3)
         End If
         xlApp = Nothing
         xlBook = Nothing
         xlSheet = Nothing
         range = Nothing
     End Sub

· 5
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @RyanG-7680 ,
I need more information to analyze your problem.
Which line of the code throw the exception? Are you unable to access the path offline?

0 Votes 0 ·
RyanG-7680 avatar image RyanG-7680 XingyuZhao-MSFT ·

My apologies.

 xlBook = xlApp.Workbooks.Open(CurrentYearPath)

I can access the target file using file explorer, but not using the Excel Object. As I mentioned, there are text files, also stored on the same OneDrive account that I can read with no problem.

0 Votes 0 ·

Hi @RyanG-7680 ,
I make a test on my side, and find that the code you provided can successfully access Excel file offline.

Check if the folder of excel file is available offline, or try to use another excel file to test again.

0 Votes 0 ·
Show more comments

0 Answers