Below is my code that is giving me an :Invalid Qualifier error. I can create a folder on the desktop just fine, then I want to be able to add .txt files to it, so I assumed using the variable for FolderPath would be the way to go but that does not seem to be the case. If I do a Debug.Print FolderPath I can see the exact path that I want, however if I use that FolderPath variable down on the line with Set Text File it does not work. What is the best way to accomplish this?
VBA Code:
Dim FolderName As String
Dim DesktopPath As String
Dim FolderPath As String
Dim FSOCreateFolder As Object
Dim DisplayFolderCreated As Boolean
'Find Desktop path location
DesktopPath = Environ("USERPROFILE") & "\Desktop\"
'Define folder name to create on the desktop
FolderName = "Test Folder"
'Folder Path
FolderPath = DesktopPath & FolderName
'Create FSO Object
Set FSOCreateFolder = CreateObject("Scripting.FileSystemObject")
'Check Specified Folder exists or not
If Not FSOCreateFolder.FolderExists(FolderPath) Then
'Create Folder
MkDir FolderPath
DisplayFolderCreated = True
Else
DisplayFolderCreated = False
End If
Debug.Print FolderPath
'----------//////////----------//////////----------//////////----------//////////
Dim FSOTxt As Object
Dim TextFile As Object
Set FSOTxt = CreateObject("Scripting.FileSystemObject")
Set TextFile = FSOTxt.CreateTextFile(FolderPath.txt, True, True)
TextFile.Write "Testing123"