Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-20-2014, 03:17 AM
femagu femagu is offline Word VBA: Helping someone new Windows 8 Word VBA: Helping someone new Office 2013
Novice
Word VBA: Helping someone new
 
Join Date: Feb 2014
Posts: 2
femagu is on a distinguished road
Default Word VBA: Helping someone new

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
- TOC/TOF/TOT creation (ca. 10s)
--> 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.
Reply With Quote
  #2  
Old 02-21-2014, 09:33 AM
femagu femagu is offline Word VBA: Helping someone new Windows 8 Word VBA: Helping someone new Office 2013
Novice
Word VBA: Helping someone new
 
Join Date: Feb 2014
Posts: 2
femagu is on a distinguished road
Default

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!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrong hyphenation NobodysPerfect Word 1 02-04-2014 05:46 AM
Word VBA: Helping someone new At wit's end trying understand styles for numbering/bullet levels in MS Word gopher_everett Word 3 02-22-2013 05:19 PM
Word VBA: Helping someone new Symbols I don't understand appearing in word suzantn Word 2 11-22-2012 08:36 AM
Word VBA: Helping someone new Open With (Boy I did something wrong) lostsoul62 Word 1 12-27-2011 07:29 PM
Word VBA: Helping someone new Demo gone wrong RyanNIF Publisher 1 10-19-2011 05:55 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft