stitu
asked on
How can we identify font styles of a MS Word document template?
How can we identify font styles of a MS Word document template? I need to get the styles like H1, H2, etc and save the corresponding style configuration(font, size, color, weight etc) in the DB. How is this possible?
ASKER
The part of the problem is solved. Thanks a bunch. I am afraid I am not aware about managing this information into database and will be needing help on this one.
The assumption that I am making now is that you have created a Jet (Access) database with an appropriate table to receive the data.
This uses ADO, so you will need to make a reference to the
Microsoft Access Data Objects library (via Tools/References in your VBA window).
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim doc As Word.Document
Dim sty As Word.Style
cnn.Open "Provider=Microsoft.Jet.OL EDB.4.0; Data Source=C:\MyDataFolder\MyD ata.db;"
rst.Open "MyFontsTable", cnn, adOpenDynamic, adLockPessimistic, adCmdTableDirect
Set doc = Application.Documents.Open ("c:\progr am files\microsoft office\templates\normal.do t")
For Each sty In doc.Styles
rst.AddNew
rst.Fields("Style Name") = sty.NameLocal
rst.Fields("Font Name") = sty.Font.Name
rst.Fields("Font Size") = sty.Font.Size
'Any other font properties that you want to save to the database
rst.Update
Next sty
rst.Close
cnn.Close
This uses ADO, so you will need to make a reference to the
Microsoft Access Data Objects library (via Tools/References in your VBA window).
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim doc As Word.Document
Dim sty As Word.Style
cnn.Open "Provider=Microsoft.Jet.OL
rst.Open "MyFontsTable", cnn, adOpenDynamic, adLockPessimistic, adCmdTableDirect
Set doc = Application.Documents.Open
For Each sty In doc.Styles
rst.AddNew
rst.Fields("Style Name") = sty.NameLocal
rst.Fields("Font Name") = sty.Font.Name
rst.Fields("Font Size") = sty.Font.Size
'Any other font properties that you want to save to the database
rst.Update
Next sty
rst.Close
cnn.Close
ASKER
Ya. appropriate tables are ready in the database. How can we do it using DAO?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
stitu:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
Moderator, my recommended disposition is:
Accept GrahamSkan's comment(s) as an answer.
DanRollins -- EE database cleanup volunteer
Accept GrahamSkan's comment(s) as an answer.
DanRollins -- EE database cleanup volunteer
I am supposing that you know how to store the data in a database instead of printing it.
Dim doc As Word.Document
Dim sty As Word.Style
Set doc = Application.Documents.Open
For Each sty In doc.Styles
Debug.Print sty.NameLocal
Debug.Print sty.Font.Name
Debug.Print sty.Font.Size
Debug.Print sty.Font.etcetera
Next sty