I would find it really useful if there existed some application that would do the following:
Given any document in Word the application could automatically generate a module of VBA routines that, when triggered, would output the original document ‘on the fly’ including all formatting, text boxes, images, fonts etc. In other words you put the document in one end of this function/application and a set of routines comes out the other and these routines in turn will generate the original
document. It might sound silly but then with a little tweaking of the outputted code you could easily turn static documents into ones that varied their order and content according to data from the (possibly Access) database. This would enable the easy creation of reports and other data bound documents without the limitations of just putting simple merge fields in the document.
Anyone know if such a thing exists/can be done?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Generate VBA code to reconstruct a document (Office 2000 SP 1A WinXP)
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Generate VBA code to reconstruct a document (Office 2000 SP 1A WinXP)
- This topic has 9 replies, 6 voices, and was last updated 20 years, 2 months ago.
AuthorTopicWSdavidhit
AskWoody LoungerApril 2, 2005 at 2:26 am #417849Viewing 2 reply threadsAuthorReplies-
WSHansV
AskWoody LoungerApril 2, 2005 at 10:15 am #938616I don’t think this is feasible. If you want this to be applicable to arbitrary documents, you’d end up with completely unstructured information and code.
If you search Google for word document assembly, you’ll find many ready-made tools that allow you to create documents from building blocks.
-
WSdavidhit
AskWoody LoungerApril 3, 2005 at 8:49 pm #938760Thanks Hans. The sort of things that come up with such a Google search are all to do with assembling documents, usually legal contracts, from boilerplate paragraphs and putting these in a specified order. I can already do this with code I have written, it is not hard at all.
I guess what I was after was the Word equivalent of the FrontPage WYSIWYG interface, and then some.
I could construct my document and use the macro recorder to put the code together but many of the documents I wish to treat in this fashion are fairly complex, already exist
and took quite some time to design and format. It just struck me that, in principle, all the instructions must already be there, albeit in some covert form, and there might be a routine
that “works backwards” deconstructing the document and “recording” the code in reverse from which the document might be re-generated at the click of a command button.
This would mean that I coud tweak the code at various points to insert database information or vary the order or even substitute pictures in place of existing ones, etc, etc.
Do you see exactly what I mean? -
WSHansV
AskWoody Lounger -
WSStuartR
AskWoody LoungerApril 3, 2005 at 9:04 pm #938763Even if you could do this, it could never be “perfect”.
For example the placement of text boxes and graphics would need to be fixed relative to a paragraph, or to the page, or the margin. Most people who construct word documents aren’t that careful about specifying this sort of thing, and although you might be able to reproduce the appearance of the original document, any change in content could lead to a really silly result.
StuartR
-
-
-
WSchrisgreaves
AskWoody LoungerApril 2, 2005 at 4:42 pm #938622> Anyone know if such a thing exists/can be done?
The answer to your question is “yes” – someone does know.
A slightly deeper answer would be “yes – in principle”, since the specifications for the bit-by-bit layout and structure of a document are available (and are put to use by some companies who like living dangerously), it can be done, and is done.
After all, a program called “Word” manages to present a document on your monitor/printer, assembled from a serial stream of bits.I suspect that you need a more practical basis for “yes”, and here it is:
If you are prepared to specify what you mean by “re-assemble a document”, then you can do it yourself.
At the simplest level, if you define a document as “a series of text paragraphs”, then a simple VBA loop emitting each paragraph to a text file will do the job; reassembly consists of reading the text file and loading each record to a new paragraph.
Of course, that would be unformatted text, so your specification should include some descriptors that (1) name the style associated with each paragraph and (2) define each named style at the level you define. That level would include at least font name and size, enhancement, paragraph indent and space, and so on, to whatever detail you feel is necessary.
You’d probably want to include descriptors for local formatting (non-styled) within each paragraph.
And yes, you’d want to define sections and the header-footer descriptors for each.
To this point it is not a lot of work, really. It does not transport a document as we know it, but it does transport a document to a specific standard, which may well be suitable for your purposes.
In effect, you would be making a parallel definition of Microsoft’s specifications for a document. Your device would have the advantage of being switchable; I can envisage a GUI form linked to an INI file, by which you nominate just which features are to be preserved in transporting a document.
This device would serve as a mechanism for standardising documents within an installation.
Other programs, such as those that generate PDF files, almost certainly go through a procedure like this; they have to interpret the serial bit stream of a document file and transform it into their target form.
I perform similar acts when I’m cleansing large batches of documents; the client specifies what text forms are to be identified and reformatted, and we do just that. One client specifies “any text that has NOT been recognised (and styled accordingly) should be styled as UnTreated”; in effect every paragraph of text in every document is re-styled to an installation standard.
(later) ooops. You didn’t want an appliaction that could accurately dis-embody a program to/from a text file; you wanted VBA code, right? That too could be done. Instead of outputing a stream of encoded text (Hey! It looks like RTF format!!!!!) you would need to go one step further and output the VBA code. Imagine one of my procedures that is handed a range of text and told to “output the local formatting specisifactiosn for this range of text”; instead of outputing a stream of characters that can be interpreted by my code, I’d output a code that looked like, and was, VBA instructions for formatting a range of text. Those instructions would then be read into modules and the main macro in each module would be executed.
I think I’d prefer a coded text method to a VBA code method; the latter is awkward to modify.
-
WSjscher2000
AskWoody LoungerApril 2, 2005 at 7:09 pm #938643 -
WSAlanMiller
AskWoody Lounger -
WSjscher2000
AskWoody LoungerApril 4, 2005 at 7:45 pm #938921> which of RTF and HTML might give a more “faithful” rerendering in Word?
I suspect RTF, if the formatting is at all complicated. It also might be easier for you. Trying to specify, for example, a hanging indent in just a small snippet of a document, irrespective of the overall style sheet, is going to be messy.
-
WSAlanMiller
AskWoody Lounger
-
-
-
Viewing 2 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Very Quarrelsome Taskbar!
by
CWBillow
7 hours, 44 minutes ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
10 hours, 28 minutes ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
11 hours, 46 minutes ago -
Is your battery draining?
by
Susan Bradley
1 hour, 43 minutes ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
10 minutes ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
14 hours, 20 minutes ago -
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
17 hours, 34 minutes ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
1 hour, 22 minutes ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
2 hours, 13 minutes ago -
National scam day
by
Susan Bradley
1 hour, 13 minutes ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
26 minutes ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
1 day, 15 hours ago -
Tools to support internet discussions
by
Kathy Stevens
4 hours, 5 minutes ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
1 day, 6 hours ago -
AI is good sometimes
by
Susan Bradley
1 day, 22 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
1 day, 12 hours ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
2 days, 22 hours ago -
June KB5060842 update broke DHCP server service
by
Alex5723
2 days, 21 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
3 days, 1 hour ago -
Excessive security alerts
by
WSSebastian42
1 day, 16 hours ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
3 days, 10 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
1 hour, 8 minutes ago -
Seconds are back in Windows 10!
by
Susan Bradley
2 days, 22 hours ago -
WebBrowserPassView — Take inventory of your stored passwords
by
Deanna McElveen
1 day, 15 hours ago -
OS news from WWDC 2025
by
Will Fastie
1 day, 1 hour ago -
Need help with graphics…
by
WSBatBytes
2 days, 6 hours ago -
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
4 days, 2 hours ago -
Totally remove or disable BitLocker
by
CWBillow
3 days, 1 hour ago -
Windows 10 gets 6 years of ESU?
by
n0ads
3 days, 4 hours ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
4 days, 13 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.