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
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,579 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,509 questions
{count} votes