![]() |
#1
|
|||
|
|||
![]()
Hello Forum Users,
in the course of a student job I was given a word vba task. I started with NO knowledge on the topic at all. I am pretty sure that there is a whole lot to improve and that I could learn a lot from you. About the task: A SQL database creates a large html document. (I have nothing to do with that) I was told to create a word vba macro within access to create a neatly styled word and PDF file based on this html file (and a .css stylesheet). What I did: - I created a Word template with all the styles I need. - I created a .css file to make one aspect of each style unique (I used the backgorund color, varying from white to light gray.) - I created the vba macro. It actually works pretty fine (to my suprise). The only thing is that it takes 6 minutes to create a 300 pages long document. Since this document will grow larger in the future (maybe even a lot larger) I need to make it work faster. What the macro does: - Initialization (ca. 15s) + Open the templete + Insert content from html file (Stylesheet information is applied in the word document as well and used to determine which style needs to be applied for each element in the document) - Table styling (ca. 60s) + Call table sub (For Each t In .ActiveDocument.Tables) --> applying one of two table styles depending on t.Rows.Alignment --> changing t.Columns(x).wdPreferredWidthType and t.Columns(x).wdPreferredWidth for all tables of one style - Image styling (ca. 30s) + Call image sub (For Each pic In .ActiveDocument.InlineShapes) --> applying the image style --> pic.LinkFormat.SavePictureWithDocument = True - Paragraph styling (ca. 200s <-- ouch!) + applying one of 18 styles based on background color of each paragraph (the unique background color is used to determine which one) example: Code:
For Each p In .ActiveDocument.Paragraphs dX = p.Range.ParagraphFormat.Shading.BackgroundPatternColor p.Range.ParagraphFormat.Shading.BackgroundPatternColor = wdColorAutomatic Call ParaStyler(dX, p, objWord) Next ----------------------------------------- Private Sub ParaStyler(dX, p, objWord) With objWord Select Case dX Case 16777215 p.Range.Style = .ActiveDocument.Styles("MyStyle1") Case 16646143 p.Range.Style = .ActiveDocument.Styles("MyStyle2") End Select End With End Sub --> Self-explaining - Finalization (ca. 20 s) --> Chaning minor things here and there - Saving --> Save Word File --> Save PDF File __________________________________ __________________________________ Thanks for reading so far! I want to make this work faster and to learn about vba. I would have no problem to change the entire concept (even if i am a little proud to have come that far). What are your very first thought after you have read this? What would you have done differently? Which mistakes are obvious to you? THANK YOU VERY MUCH! Greetings from Cologne, Germany. Last edited by femagu; 02-20-2014 at 04:56 AM. |
#2
|
|||
|
|||
![]()
I am now aware that I have done everything wrong that can be done wrong when I submitted this thread:
- It has a weakly chosen title - It is placed in the wrong category (could so. move it to Word VBA?) - I didnt' tell you anything about my setup. (Strong machine: 16GB RAM, i7-Processor, Win 8, Office Pro 2013) I am sorry about that! Also, the main question is not clear: --> How would an experienced vba user (you) engage the outlined problem? To clearify the problem: There is a large html file that uses many different css-stylesheet based styles (headers, paragraphs, code blocks, tables, figures, captions, etc. The outcome needs to be a nicely looking and printable Word/PDF document. - Many different styles (Different header levels, paragraph styles (Regular, Code, Notes, Captions) - Consistently styled images and tables - Table of Content, Table of Figures, Table of tables (?!) - ... A short outline of your first thoughts engaging this problem would be very helpful for someone that touched vba for the first time two weeks ago (me). Again, thank you very much! |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Wrong hyphenation | NobodysPerfect | Word | 1 | 02-04-2014 05:46 AM |
![]() |
gopher_everett | Word | 3 | 02-22-2013 05:19 PM |
![]() |
suzantn | Word | 2 | 11-22-2012 08:36 AM |
![]() |
lostsoul62 | Word | 1 | 12-27-2011 07:29 PM |
![]() |
RyanNIF | Publisher | 1 | 10-19-2011 05:55 AM |