Hi,
I'm farely new at VBA and I need could need some help.
I'm trying to make a macro where I can copy excel cells to notepad, example:
I want the data in A1 copied in a notepadfile and be named with data in B1, then A2 copied in a notepadfile and be named with data in B2, then A3 copied in a notepadfile and be named with data in B3........ and so on.
I've tried with this macro put cant get it to work. it allways copies A1:A411 into B1 and thats it.
Sub ExportToNotepad()
Dim rngEachCell As Range
For Each rngEachCell In Sheets("hex").Range("A1:A411").Cells
WriteRangeToTextFile Range("B1:B411"), rngEachCell.Value, vbTab
Shell "notepad.exe " & rngEachCell.Value, vbMaximizedFocus
Next rngEachCell
End Sub
Sub WriteRangeToTextFile(Source As Range, Path As String, Delimiter As String)
Dim oFSO As Object
Dim oFSTS As Object
Dim lngRow As Long, lngCol As Long
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFSTS = oFSO.CreateTextFile(Path, True)
For lngRow = 1 To Source.Rows.Count
For lngCol = 1 To Source.Columns.Count
If lngCol = Source.Columns.Count Then
oFSTS.Write Source.Cells(lngRow, lngCol).Text & vbCrLf
Else
oFSTS.Write Source.Cells(lngRow, lngCol).Text & Delimiter
End If
Next lngCol
Next lngRow
oFSTS.Close
Set oFSTS = Nothing
Set oFSO = Nothing
End Sub
Does the filenames in B1:B411 have to have the path where i want it saved?
Hope somebody can help me, thanx!
I'm farely new at VBA and I need could need some help.
I'm trying to make a macro where I can copy excel cells to notepad, example:
I want the data in A1 copied in a notepadfile and be named with data in B1, then A2 copied in a notepadfile and be named with data in B2, then A3 copied in a notepadfile and be named with data in B3........ and so on.
I've tried with this macro put cant get it to work. it allways copies A1:A411 into B1 and thats it.
Sub ExportToNotepad()
Dim rngEachCell As Range
For Each rngEachCell In Sheets("hex").Range("A1:A411").Cells
WriteRangeToTextFile Range("B1:B411"), rngEachCell.Value, vbTab
Shell "notepad.exe " & rngEachCell.Value, vbMaximizedFocus
Next rngEachCell
End Sub
Sub WriteRangeToTextFile(Source As Range, Path As String, Delimiter As String)
Dim oFSO As Object
Dim oFSTS As Object
Dim lngRow As Long, lngCol As Long
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFSTS = oFSO.CreateTextFile(Path, True)
For lngRow = 1 To Source.Rows.Count
For lngCol = 1 To Source.Columns.Count
If lngCol = Source.Columns.Count Then
oFSTS.Write Source.Cells(lngRow, lngCol).Text & vbCrLf
Else
oFSTS.Write Source.Cells(lngRow, lngCol).Text & Delimiter
End If
Next lngCol
Next lngRow
oFSTS.Close
Set oFSTS = Nothing
Set oFSO = Nothing
End Sub
Does the filenames in B1:B411 have to have the path where i want it saved?
Hope somebody can help me, thanx!