PDA

View Full Version : copy tables from word without repeating header



mvakharia
06-02-2020, 03:25 AM
26782Hi Paul, This is Mayur (continuing from stackoverflow) as there is no option to attach files. Hope you are same macropod file:///C:/Users/User/AppData/Local/Temp/msohtmlclip1/01/clip_image001.gif
Attached here with are the two invoice files... I am trying to copy the tables (with only header row: with keyword "Description").
Following is the code that i am using. Also wanted to copy Invoice / sales order number with Date and paste in column E.
The instr function is unable to find "Description". Hope you have all the details now. Sorry for the confusion and taking so much time of yours.

macropod
06-02-2020, 03:42 AM
Cross-posted (and answered before posting here) at: https://stackoverflow.com/questions/62131284/copy-tables-from-word-without-repeating-header
Please read VBA Express' policy on Cross-Posting in Rule 3: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3

mvakharia
06-02-2020, 04:04 AM
[QUOTE=macropod;402740]Cross-posted (and answered before posting here) at:
Yes sir, since there was no option to upload files in stackoverflow :(

snb
06-02-2020, 04:16 AM
Sub M_snb()
with getobject("G:\OF\invoice.docx")
For Each it In .Tables
If InStr(it, "Description") Then c00 = c00 & vbCrLf & it
Next
.close 0
end with

CreateObject("scripting.filesystemobject").createtextfile("G:\OF\tbles.csv").write Replace(Join(Filter(Split(c00, vbCr & Chr(7) & vbCr & Chr(7)), "Description", 0), vbCrLf), vbCr & Chr(7), ",")
Workbooks.Open "G:\OF\tbles.csv"
End Sub

macropod
06-02-2020, 05:20 AM
[QUOTE=macropod;402740]Yes sir, since there was no option to upload files in stackoverflow :(
Quite irrelevant. When you joined this forum you agreed to abide by its rules. In any event, as per the line you quoted, the problem was already solved at StackOverflow before you posted here.

mvakharia
06-02-2020, 05:35 AM
[QUOTE=mvakharia;402744]
Quite irrelevant. When you joined this forum you agreed to abide by its rules. In any event, as per the line you quoted, the problem was already solved at StackOverflow before you posted here.

Unfortunately still not working as desired and that's the main reason I wanted to share the file. With your revised Instr formula it does go inside the loop but deletes the first row which in case 1 is has two row header.
Also unable to retrieve the Sales Order no. and Date from both the word files.
Sorry for all the trouble and really appreciate all your help. God bless you!

macropod
06-02-2020, 03:13 PM
[QUOTE=macropod;402751]ith your revised Instr formula it does go inside the loop but deletes the first row which in case 1 is has two row header.
Also unable to retrieve the Sales Order no. and Date from both the word files.
If you want help, kindly continue the discussion at StackOverflow. I have no intention of carrying on the discussion across two different forums. Thread closed.