wName for folder?

SpeedyKevin

New Member
Joined
Apr 26, 2019
Messages
17
Hello all!

I'm trying to write certain cells to a text file. What I have it doing is allowing me to type in the name to which a folder and file will be created. The file naming works and folder is created but I can't seem to get the bolded part to work. Any suggestions? Thanks!




Sheets("OVERALL_CLIPS").Select
wName = InputBox("Enter file name")
If wName = "" Then Exit Sub



If Len(Dir(CurDir & "\Stoplight_Feedback" & wName, vbDirectory)) = 0 Then
MkDir CurDir & "\Stoplight_Feedback" & wName
End If





WriteRangeToTextFile Range("D6:D8"), "Stoplight_Feedback\(wName)" & (wName & "-VC1.m3u8"), vbTab
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
How 'bout this
Code:
Sub Test()    Dim FSO As Object
    Dim oFile As Object
    Dim c As Range
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Sheets("OVERALL_CLIPS").Select
    wName = InputBox("Enter file name")
    If wName = "" Then Exit Sub
    ChDir "C:\Junk"
    vDir = "C:\Junk"
    If Len(Dir(vDir & "\Stoplight_Feedback" & wName, vbDirectory)) = 0 Then
        MkDir vDir & "\Stoplight_Feedback" & wName
    End If
    wFldr = vDir & "\Stoplight_Feedback" & wName & "\"
    wName = wName & "-VC1.m2u8"
    Set oFile = FSO.CreateTextFile(wFldr & wName)
    Range("D6:D8").Select
    For Each c In Selection
        oFile.Write c.Value & Chr(13) & Chr(10)
    Next c
    oFile.Close
End Sub
 
Upvote 0
How 'bout this
Code:
Sub Test()    Dim FSO As Object
    Dim oFile As Object
    Dim c As Range
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Sheets("OVERALL_CLIPS").Select
    wName = InputBox("Enter file name")
    If wName = "" Then Exit Sub
    ChDir "C:\Junk"
    vDir = "C:\Junk"
    If Len(Dir(vDir & "\Stoplight_Feedback" & wName, vbDirectory)) = 0 Then
        MkDir vDir & "\Stoplight_Feedback" & wName
    End If
    wFldr = vDir & "\Stoplight_Feedback" & wName & "\"
    wName = wName & "-VC1.m2u8"
    Set oFile = FSO.CreateTextFile(wFldr & wName)
    Range("D6:D8").Select
    For Each c In Selection
        oFile.Write c.Value & Chr(13) & Chr(10)
    Next c
    oFile.Close
End Sub

Hey GR00007,

Thanks for the reply! Almost got it working! If I wanted it to write other cells to notepad would i just copy and paste the segment like this?

wFldr = vDir & "\Stoplight_Feedback" & wName & ""
wName = wName & "-VC1.m3u8"
Set oFile = FSO.CreateTextFile(wFldr & wName)
Range("D6:D8").Select
For Each c In Selection
oFile.Write c.Value & Chr(13) & Chr(10)
Next c
oFile.Close

wFldr = vDir & "\Stoplight_Feedback" & wName & ""
wName = wName & "-VC2.m3u8"
Set oFile = FSO.CreateTextFile(wFldr & wName)
Range("D12:D14").Select
For Each c In Selection
oFile.Write c.Value & Chr(13) & Chr(10)
Next c
oFile.Close
 
Upvote 0
Hey GR00007,

Thanks for the reply! Almost got it working! If I wanted it to write other cells to notepad would i just copy and paste the segment like this?

wFldr = vDir & "\Stoplight_Feedback" & wName & ""
wName = wName & "-VC1.m3u8"
Set oFile = FSO.CreateTextFile(wFldr & wName)
Range("D6:D8").Select
For Each c In Selection
oFile.Write c.Value & Chr(13) & Chr(10)
Next c
oFile.Close

wFldr = vDir & "\Stoplight_Feedback" & wName & ""
wName = wName & "-VC2.m3u8"
Set oFile = FSO.CreateTextFile(wFldr & wName)
Range("D12:D14").Select
For Each c In Selection
oFile.Write c.Value & Chr(13) & Chr(10)
Next c
oFile.Close

Oh wait I think i got it! Thanks! Appreciate the help!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top