Sargad_Strut
New Member
- Joined
- Mar 28, 2014
- Messages
- 44
Hi guys,
So this is what my workbook does in short:
Opens up and updates a table from .accdb
Updates relevant data from an external source
I then need to save this data back into a text file to rewrite back into the database. The problem is that I'm getting "" at the start and end of every row in the txt file. Also tried to save it as .csv in which the quotation marks actually are not visible, but still there when I try to read the file back into the database.
2 Questions:
Does this happen because CellData is declared as a string?
Pretty obvious but, how can i solve this?
Thank you!
Part of my code:
Sub GenerateTextfile()
Dim FilePath As String
Dim CellData As String
Dim LastCol As Integer
Dim LastRow As Integer
LastCol = 4
LastRow = Blad2.Range("H2").Value
Blad2.Range("A2").Activate
CellData = ""
FilePath = "P:\Tobias\Update\<wbr>Output\NewData.txt"
Open FilePath For Output As #2
For i = 1 To LastRow
For j = 1 To LastCol
If j = LastCol Then
CellData = CellData + Trim(ActiveCell(i, j).Value)
Else
CellData = CellData + Trim(ActiveCell(i, j).Value) + vbTab
End If
Next j
Write #2, CellData
CellData = ""
Next i
Close #2
End Sub
So this is what my workbook does in short:
Opens up and updates a table from .accdb
Updates relevant data from an external source
I then need to save this data back into a text file to rewrite back into the database. The problem is that I'm getting "" at the start and end of every row in the txt file. Also tried to save it as .csv in which the quotation marks actually are not visible, but still there when I try to read the file back into the database.
2 Questions:
Does this happen because CellData is declared as a string?
Pretty obvious but, how can i solve this?
Thank you!
Part of my code:
Sub GenerateTextfile()
Dim FilePath As String
Dim CellData As String
Dim LastCol As Integer
Dim LastRow As Integer
LastCol = 4
LastRow = Blad2.Range("H2").Value
Blad2.Range("A2").Activate
CellData = ""
FilePath = "P:\Tobias\Update\<wbr>Output\NewData.txt"
Open FilePath For Output As #2
For i = 1 To LastRow
For j = 1 To LastCol
If j = LastCol Then
CellData = CellData + Trim(ActiveCell(i, j).Value)
Else
CellData = CellData + Trim(ActiveCell(i, j).Value) + vbTab
End If
Next j
Write #2, CellData
CellData = ""
Next i
Close #2
End Sub