Hi,

I have some code that gets a file's path. However, the files I access are now on SharePoint. It appears that I am unable to use the code as is now. Am I doing something wrong? Is there a work around to this? See code below. The path I get with the code is https://sharepoint.com... (It's the web address) I get the "Bad file name or number" error on: If Dir(myFileName & SaveExt) = "" Then.


Option Explicit


Public Sub ExportToNotepad()
Dim ws  As Worksheet
Dim wsData As Variant
Dim myFileName As String
Dim FN As Integer
Dim p As Integer, q As Integer
Dim path As String
Dim myString As String
Dim lastrow As Long
Set ws = Worksheets("Sheet1")
lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row
path = Application.ThisWorkbook.path & "\"
Dim x As Long
Dim VerExt As String
Dim SaveExt As String
Dim Saved As Boolean

Saved = False
wsData = ws.Cells(1, 1).Value
x = 2
VerExt = "_"
SaveExt = ".txt"
myFileName = wsData
myFileName = path & myFileName
    
If wsData = "" Then Exit Sub

If Dir(myFileName & SaveExt) = "" Then
   
    MsgBox myFileName & SaveExt
    For q = 2 To lastrow
        If Len(ws.Cells(q, 1).Text) Then myString = myString & ws.Cells(q, 1).Text & vbCrLf
        FN = FreeFile
        Open myFileName & SaveExt For Output As #FN
        Print #FN, Left(myString, Len(myString) - 2)
        Close #FN
    Next q
    myString = ""
Else

     Application.DisplayAlerts = False
  Do While Saved = False
    If Dir(myFileName & VerExt & x & SaveExt) = "" Then
      MsgBox myFileName & VerExt & x & SaveExt
      Saved = True
    Else
      x = x + 1
    End If
  Loop
    Application.DisplayAlerts = True
  
For q = 2 To lastrow
        If Len(ws.Cells(q, 1).Text) Then myString = myString & ws.Cells(q, 1).Text & vbCrLf
        FN = FreeFile
        Open myFileName & VerExt & x & SaveExt For Output As #FN
        Print #FN, Left(myString, Len(myString) - 2)
        Close #FN
    Next q
    myString = ""
End If

    


End Sub