Help export a table content to txt file using a vba

mihaibantas

New Member
Joined
Oct 14, 2016
Messages
12
Hi all, I would say from the very beginning that I am not an expert in the VBA code...
that's why I come with the request to help me with an answer to a problem

So my problem is:
1. I want to export a table to a text file...till now is simple (I also give a google search after a vba code model)
2. now comes the complicated part...the table exported in txt format must have the following configuration<code>:

(pl:cell-value 1 "B" "Test 1")</code>
<code>(pl:cell-value 1 "C" "OK 1")</code>
<code>(pl:cell-value 2 "B" "Test 2")
</code><code><code>(pl:cell-value 2 "C" "OK 2")</code></code>
<code>(pl:cell-value 3 "B" "Test 3")
</code>
<code><code>(pl:cell-value 3 "C" "OK 3")</code></code>
<code></code>
<code><code>
1 - represent Row</code>
</code><code>
B
- represent Column </code><code><code></code></code><code>
Test 1
- represent CellValue on B1 </code><code><code></code></code><code>
(pl:cell-value "" )- represent un specific text
</code>
<code></code><code></code><code>The range of table is B1:C3</code><code>
</code>
<code>
Thank you for your time to my problem </code><code></code>
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
This macro should do what you want, simply replace what I have highlighted in red with the full path, filename and extension for the text file you want to write the output to.
Code:
[table="width: 500"]
[tr]
	[td]Sub TableToText()
  Dim N As Long, R As Long, C As Long, LastRow As Long, FF As Long, Result As String
  LastRow = Cells(Rows.Count, "B").End(xlUp).Row
  For R = 1 To LastRow
    For C = 2 To 3
      N = N + 1
      Result = Result & vbCrLf & "(pl:cell-value " & R & " """ & Mid("BC", C - 1, 1) & """ """ & Cells(R, C).Value & """)"
    Next
  Next
  FF = FreeFile
  Open "YourPathAndFilename" For Output As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FF]#FF[/URL] 
    Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FF]#FF[/URL] , Result
  Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FF]#FF[/URL] 
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,167
Members
452,615
Latest member
bogeys2birdies

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