Identify the number of a Word table (Selected or by Title) - excel

I'm trying to program a macro in excel to export data to a word report. This data will go into several Word tables. All data transfer commands are now ready and working. However, in order to make this transfers more dynamic, I am inserting Titles and creating bookmarks for all tables into word report.
The problem is:
Via excel macro, I am able to select the Word tables through the following code:
oDoc.Bookmarks("Table_name").Range.Select
However, I cannot transfer the data to a specific cell of this table.
I know the by Word there is this command, but I can't use with Excel.
ActiveDocument.Range(0,Selection.Paragraphs(1).Range.End).Tables.Count)
Would anyone know how to help me?
Before that I was transferring the data referencing the table number but the problem is that whenever we revise the report to include new tables my reference ends up getting lost and I have to do table count again to transfer the data in the right table .
Well, that's it! Thanks in advance if anyone can help me.

It entirely depends on how your document is constructed. If the bookmarks enclose content, then you can use:
oDoc.Bookmarks("Table_name").Range.Tables(1)

MS Word does not give each one a name, so you have to come up with your own system.
When you create the document with all the tables, you can give each one a name... using the Table.Descr property.
ActiveDocument.Tables(1).Descr = "myTable"
Then when you look for them, loop thru them and find that Descr
For Each t In ActiveDocument.Tables
If t.Descr = "myTable" Then
' do something
End If
Next
Or you can set up some constants for the Index if that helps.
Or you can create one routine that sets up variables by scanning the document that you would need to run only once.

Related

Generate a table in word using excel data

Data in this list is required to be formatted in a table in MS Word so I can make a simple catalog with similar to this I have a long list of items so I need a faster and easier way to prepare the catalog, I intend to save it as a PDF afterwards, by placing company logo in page header. Any easier way to do this without having to pay for a catalog service is much appreciated
You can simply take the whole table from excel to word by selecting the whole table in excel then copying it and pasting it in the word file.
Another way is to create a table in the word file having exact number of rows and columns in your excel table. And than pasting the excel table data to the word table.
I hope this helps you.

Dynamic Hyperlink in Table Issue

I am working with a Table inside of excel. I would like to have it so the number documents in the table are hyperlinks back to my file folder.
I am finding that the Hyperlink formula will not work in the table. Using the same formula outside of a table it seems to work.
I have the below formula in the hyperlink link_location:
=LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1))-1)&
INDEX(Sheet2!$H$3:$I$19,MATCH(LEFT([#Number],1),Sheet2!$H$3:$H$19,0),2)&
"\"&[#Number]
In the above code;
The first part of the code identifies the file location.
Index in the code returns the name Processes for P for the Number (P009).
Returns: R:\Integrity Management\2. Document Control Management\Processes\P006
Error window coming up says: Cannot open specified file.
Ultimately it would be great if the "Number" items would hold the hyperlink instead of a separate column.
Current table set up
Not sure why. The links are currently working as intended today. If anyone has a reason why this issue occurred please let me know.

Copy and paste Excel rows between two workbooks based on criteria from exported Access data

I have no previous experience in Access, VBA coding or in Excel macros prior to teaching myself the past month via these forums. Thank you forums and contributors. I have enjoyed my Access learnings so far, the challenge that it has provided and appreciate any help that I can get. As such, the code and methods that I have used to this point may well be convoluted and confusing. I will do my best to provide relevant details and accurate terminology.
I work in a lab and I am creating an Access Form for semi-automated reporting. Samples are received from clients and are logged into the Excel Table R&D Log. The worksheet is InProcess. Samples are sorted based on the site in which they originate and given a one or two letter site code (G, D, WH, etc.) and an ID "yy-000" in separate Excel columns (i.e. D 18-096). Samples may be submitted for multiple analyses (Metals, Water, Soil, etc.) and may even have multiple rows of reporting if multiple analytes are identified in the sample. There are several other columns, such as receipt date, reporting date, units, etc. Once samples are reported, I manually copy and paste them into the Archived worksheet, and delete the record and blank row from the InProcess worksheet. Since one sample may have multiple analyses and even more potential results, each record would be reported on a new Excel row (with the same D 18-096 ID number). Thus, there is not a single unique identifier or primary key for each sample in the current format. R&D Log is updated manually by lab technicians and the worksheet InProcess is a linked table in an Access Database.
The Access Database is using two combo boxes on a Form frmInProcess to filter a Query qryInProcess of the linked table. The combo boxes are filtering the report destination (one client may receive multiple site codes) and the analysis (reports are separated based on type of analysis). The Query is also filtering out blank results and blank dates, so only completed samples will appear on the filtered Form. I have generated VBA code to this point that will export the Form to a .pdf, save the file with unique filename, and open outlook to mail out the report. I have also managed to export the filtered Form frmInProcess to an Excel file Access Test (not the linked file).
What I would like to do now is to automate the transfer of completed test results from the Excel worksheet R&D Log: InProcess to R&D Log: Archived and delete the record from the InProcess worksheet. I am not sure if I can export the filtered Form into a linked Excel table, or if I must use a separate Excel file (or if it even matters for simplicity of code?). I would now like to read the exported filtered Form in Excel Access Test, lookup matching rows in R&D Log based on several criteria (site, ID, Analysis, Analyte, Report Date) and automate the transfer of records between R&D Log worksheets. End result being that Access generates reports for completed tests, and the records are removed from InProcess testing and transferred to Archived testing in Excel. I am guessing that I may need to close the Access application and perform this in Excel. Hope this is easy enough to follow.
Thank you.
In my experience, importing an Excel document into a temporary NEW (or totally empty) Access table is usually the easiest way to go. Then you do not have to worry about cell references like you do in Excel VBA. Even if the Excel document has old data in it with just a few new changes each time, importing it into a temporary Access table could be the simplest way to go, because then you can compare the data in this table with the data in another, permanent Access table and update the latter based on the former.
As far as the original Excel file, if you need to delete rows there, it might be quicker to export a new Excel file with just the data the old one is supposed to end up with, and then use VBA to delete (or - safer! - rename) the old file.
So the development process goes something like this:
Save import steps by first importing an Excel file via Access' ribbon options "External Data" (tab) ->"Excel" and when you finish, be sure to check the "Save import steps" box and note the name you give the "saved import" because you will need that in your VBA code.
In Access, write a function for deleting the table. The VBA code is:
Const cTable = "MyExcelTempTable"
If TableExists(cTable) Then
DoCmd.DeleteObject acTable, cTable
End If
Now you can test your delete function on the data you imported.
Write VBA code to import the same spreadsheet to create the same table:
Const cSavedImport = "Import-MyExcelTempTable"
' Import the Excel file
DoCmd.RunSavedImportExport cSavedImport
Write more VBA function(s) to check the imported table for bad data and then to copy it into the permanent table. You might be updating existing records or adding new ones. Either way, you could use Access queries or SQL to do this and run them from VBA.
Write a VBA function to rename the old Excel file. (You could use an InputBox if the Excel file name is different each time. I do this for importing Excel files, and I set a default value so I do not have to type as much.)
Write a VBA function to export the new version of the Excel file.
Make yourself a button on a form that, when clicked, runs a VBA function. Inside that function, run Steps 2 through 6, above.
I am not sure my answer exactly matches what you are trying to do, but hopefully you get enough of a picture of the workflow to figure out the details of what you need.

Access VBA, take table data and paste/insert it into another table at the end

I have a dataset that is imported from excel into access in a new table. I want to take this data and "add it" to the end of a larger data set as the main table is updated daily with relevant information. Not too experienced with VBA, however, this I cannot wrap my head around as I am normally experienced with Excel. Let me know if there is anything else I can do to help.
...from excel into access in a new table... If the data is already in your Access database, just make an INSER INTO query. No need of VBA
Add records to a table by using an append
query
And after you are done, make sure you clear that temp table where you import your data, with another query that deletes all records.

MS Access - Data in top row appears and disappears when focus on the cell changes.

Its a bit of a weird one but I have a linked table within my database. The table is an excel table with identical field headings and data types and until recently has worked fine however now when I traverse the linked table in Access the data will change every other move, changing from the original row to show data in the row below. Iv had a script output the values of the top row and it displays normally however I cant append this linked table into anything and I assume its this glitch.
Im stumped and would love any ideas as to how this happened and how it can be fixed.
This is an unusual post as I've never quite heard of this type issue. To sanity check things I would suggest that you delete your excel table from the navigation pane in Access - and then relink it.
So then perhaps I didn't understand, and I am wondering what is meant in your first post by: "The table is an excel table with identical field headings and data types"
A link to excel is a qualified "table" so to speak. You should be able to double click on it within Access, it opens in data sheet view and you see all the data but you can't write to it. You can't write back into the excel.
You can query it....
You can append the query results of the excel into a true Access table.

Resources