PsycholoJackal
New Member
- Joined
- Dec 10, 2019
- Messages
- 3
Hi all,
For my project, I want to be able to have excel in VBA deliver usernames to 2 existing notepads that's in a folder. I made it so that it takes up to 10 usernames. My issue here is that sometimes I only need to deliver 1 username but in the text file it also delivers the empty cells which becomes the empty lines in the notepad. Any way to make it to not copy the blank cells or have it delete the blank lines? Code:
Option Explicit
Public Sub XLRangeToNotepad()
Dim iPtr As Integer
Dim sFileName As String
Dim intFH As Integer
Dim oCell As Range
sFileName = "C:\Users\" & Environ("UserName") & "\Desktop\TEST LOGOFF\Iron\logoff-users.txt"
Close
intFH = FreeFile()
Open sFileName For Append As intFH
For Each oCell In Range("B2:B11")
Print #intFH, oCell.Value
Next oCell
Close intFH
sFileName = "C:\Users\" & Environ("UserName") & "\Desktop\TEST CLEAN\Iron\clear-users.txt"
Close
intFH = FreeFile()
Open sFileName For Append As intFH
For Each oCell In Range("B2:B11")
Print #intFH, oCell.Value
Next oCell
Close intFH
MsgBox "Done!"
End Sub
For my project, I want to be able to have excel in VBA deliver usernames to 2 existing notepads that's in a folder. I made it so that it takes up to 10 usernames. My issue here is that sometimes I only need to deliver 1 username but in the text file it also delivers the empty cells which becomes the empty lines in the notepad. Any way to make it to not copy the blank cells or have it delete the blank lines? Code:
Option Explicit
Public Sub XLRangeToNotepad()
Dim iPtr As Integer
Dim sFileName As String
Dim intFH As Integer
Dim oCell As Range
sFileName = "C:\Users\" & Environ("UserName") & "\Desktop\TEST LOGOFF\Iron\logoff-users.txt"
Close
intFH = FreeFile()
Open sFileName For Append As intFH
For Each oCell In Range("B2:B11")
Print #intFH, oCell.Value
Next oCell
Close intFH
sFileName = "C:\Users\" & Environ("UserName") & "\Desktop\TEST CLEAN\Iron\clear-users.txt"
Close
intFH = FreeFile()
Open sFileName For Append As intFH
For Each oCell In Range("B2:B11")
Print #intFH, oCell.Value
Next oCell
Close intFH
MsgBox "Done!"
End Sub