VB .net accessing excel files offline

Ryan G 1 Reputation point
2021-03-09T21:08:22.89+00:00

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()
        lstMemberList.Clear()
        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)
                lstMemberList.Add(mMember)
            Next
        End If
        xlBook.Close()
        xlApp.Quit()
        KillExcel()
        xlApp = Nothing
        xlBook = Nothing
        xlSheet = Nothing
        range = Nothing

    End Sub
Microsoft 365 and Office | Development | Other
Developer technologies | VB
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.