Rafael:
Although I am no expert with Word automation I have 'figured out' enough to be 
dangerous.


This is the word set up method:
*setup MS Word
wait window "Setting Microsoft Word Document Defaults..." nowait
oWord = createobject("Word.Application")
oWord.Documents.Add()
with oWord.Options
  .CheckSpellingAsYouType = thisform.container3.chkAlerts.value
  .CheckGrammarAsYouType = thisform.container3.chkAlerts.value
  .SuggestSpellingCorrections = thisform.container3.chkAlerts.value
  .SuggestFromMainDictionaryOnly = thisform.container3.chkAlerts.value
  .CheckGrammarWithSpelling = thisform.container3.chkAlerts.value
  .ShowReadabilityStatistics = thisform.container3.chkAlerts.value
  .EnableSound = thisform.container3.chkAlerts.value
  .AnimateScreenMovements = thisform.container3.chkAlerts.value
endwith
with oWord.ActiveWindow
  .DisplayScreenTips = thisform.container3.chkAlerts.value
  .View.ShowAnimation = thisform.container3.chkAlerts.value
  .ActivePane.View.Type = 3  &&select wdPrintView -- select a print view to the 
document...
endwith
with oWord.ActiveDocument
  .ShowGrammaticalErrors = thisform.container3.chkAlerts.value
  .ShowSpellingErrors = thisform.container3.chkAlerts.value
endwith
oWord.DisplayAlerts = thisform.container3.chkAlerts.value
if thisform.container3.chkActivate.value then
  oWord.Visible = .t.  &&must stay visible or the pages are not formed 
correctly...set throttle?
  toplogo.windowstate = 1        &&minimize the main window; a 2 maxs the window
  oWord.Application.Activate
  doevents
endif
wait clear


Here is the graphic insert method:
oWord.ActiveDocument.Tables.Add(oWord.Selection.Range, 1, 1)
with oWord.Selection.Tables(1)
  .Borders(-2).LineStyle = 0     &&wdBorderLeft    equals wdLineStyleNone
  .Borders(-4).LineStyle = 0     &&wdBorderRight
  .Borders(-1).LineStyle = 0     &&wdBorderTop
  .Borders(-3).LineStyle = 0     &&wdBorderBottom
  .Borders(-7).LineStyle = 0     &&wdBorderDiagonalDown
  .Borders(-8).LineStyle = 0     &&wdBorderDiagonalUp
  .Borders(-6).LineStyle = 0     &&wdBorderVertical
  .Borders.Shadow = .f.
  .PreferredWidthType = 3        &&wdPreferredWidthPoints
  .PreferredWidth = 0.85 * 72 
  .Rows.HeightRule = 2           &&wdRowHeightExactly
  .Rows.Height = 0.85 * 72
  .Rows.AllowBreakAcrossPages = .t.
  .Rows.WrapAroundText = .t.
  .Rows.HorizontalPosition =  -999998    &&wdTableLeftMargin
  .Rows.RelativeHorizontalPosition = 0  &&wdRelativeHorizontalPositionMargin
  .Rows.DistanceLeft = 0   &&text aroubd table
  .Rows.DistanceRight = 0  &&text around table
  .Rows.VerticalPosition = 0.15 * 72 &&table position vertically from margin
  .Rows.RelativeVerticalPosition = 0  &&wdRelativeVerticalPositionMargin
  .Rows.DistanceTop = 0
  .Rows.DistanceBottom = 0 
  .Rows.AllowOverlap = .t.
endwith
with oWord.Selection
  .Range.Cells(1).PreferredWidthType = 3   &&wdPreferredWidthPoints
  .Range.Cells(1).PreferredWidth = 0.85 * 72
  .Range.Cells(1).VerticalAlignment = 1   &&wdCellAlignVerticalCenter
  .InlineShapes.AddPicture("\devscout\devils.bmp", .f., .t.)   &&don't select 
the image
  .MoveRight(1,1)   &&get out of table
endwith




Here is a header setup which will probably be enough to get you started...
*set up the header for all pages...
*set some tabs
oWord.Selection.ParagraphFormat.TabStops.ClearAll
oWord.ActiveDocument.DefaultTabStop = 0.5 * 72   &&set tabs every 0.5" 
with oWord.Selection
  with .ParagraphFormat.TabStops
    .Add(3.15 * 72, 1, 0)  &&position, center, no leader
    .Add(5.95 * 72, 2, 0)  &&position, right, no leader
    .Add(6.05 * 72, 0, 0)  &&position, left, no leader
  endwith
endwith
*add devils logo to a table
thisform.add_logo()
*add rectangle
oWord.Activedocument.Shapes.AddShape(1,2.65*72, 0.355*72, 3.1*72, 
1.0*72).select  &&type, left,top,width,height
with oWord.Selection.ShapeRange
  .LockAnchor = .t.
  .Line.Weight = 3 
  .WrapFormat.AllowOverlap = .t.
  .WrapFormat.Type = 5
endwith
oWord.Selection.Collapse(0)
*Fill out Header...line 1 
with oWord.Selection
  .Font.Name = "Arial"
  .Font.Size = 12
  .TypeParagraph
  .Font.Bold = .t.
  .TypeText(chr(9) + "NEW JERSEY DEVILS")
  .Font.Size = 10
  .TypeText(chr(9)+ "DATE:")
  .Font.Bold = .f.
  .TypeText(chr(9) + dtoc(date()))
  .TypeParagraph
  *line 2
  .TypeParagraph
  .Font.Bold = .t.
  .TypeText(chr(9) + "THE DEVILS SCOUTING SYSTEM")
  .TypeText(chr(9) + "TIME:")
  .Font.Bold = .f.
  .TypeText(chr(9) + time())
  .TypeParagraph
  *line 2
  .TypeParagraph
  .Font.Bold = .t.
  .TypeText(chr(9) + "SCOUTING REPORT")
  .TypeText(chr(9) + "PAGE:")
  .Font.Bold = .f.
  .TypeText(chr(9) + alltrim(transform(gnPage + gnPage_long_comment, 
"99,999"))) &&different page and record counts
  .TypeParagraph
  .TypeParagraph
  *line 4
  .Font.Bold = .t.
  .Font.italic = .t.
  .TypeText("PRIVILEGED & CONFIDENTIAL")
  .Font.italic = .f.
  .TypeParagraph
endwith
*Header data...add rectangle box
oWord.Activedocument.Shapes.AddShape(1,18, 117, 572, 60).select  &&type, 
left,top,width,height
with oWord.Selection.ShapeRange
  .Fill.Visible = -1   &&msoTrue
  .Fill.Solid
  .Fill.ForeColor.RGB = RGB(221, 221, 221) &&15% gray
  .Fill.Transparency = 0
  .Line.Weight = 1
  .LockAnchor = .t.
  .WrapFormat.Type = 5
  .WrapFormat.AllowOverlap = .t.
endwith
oWord.Selection.Collapse(0)
*new tabs...
oWord.Selection.ParagraphFormat.TabStops.ClearAll
oWord.ActiveDocument.DefaultTabStop = 0.5 * 72
with oWord.Selection.ParagraphFormat.TabStops
  .Add(1.10 * 72, 2, 0)  &&position, center, no leader
  .Add(1.20 * 72, 0, 0)  &&position, right, no leader
  .Add(4.00 * 72, 2, 0)  &&position, center, no leader
  .Add(4.10 * 72, 0, 0)  &&position, right, no leader
  .Add(6.25 * 72, 2, 0)  &&position, center, no leader
  .Add(6.35 * 72, 0, 0)  &&position, right, no leader  
endwith  
*Header fields...line 1
with oWord.Selection
  .Font.Name = "Arial"
  .Font.Size = 7  &&move down from top of rectangle
  .TypeParagraph
  .Font.Size = 10
  .Font.Bold = .t.
  .TypeText(chr(9)+ "SCOUT:")
  .Font.Bold = .f.
  .TypeText(chr(9) + p_scout)
  .Font.Bold = .t.
  .TypeText(chr(9) + "TEAM SCOUTED:")
  .Font.Bold = .f.
  .TypeText(chr(9) + p_home)
  .Font.Bold = .t.
  .TypeText(chr(9) + "REPORT TYPE:")
  .Font.Bold = .f.
  .TypeText(chr(9) + gcReport_type)
  .Font.Bold = .t.
  .TypeParagraph
  *Header fields...line 2
  .Font.Size = 7  &&move down from previous line
  .TypeParagraph
  .Font.Size = 10
  .Font.Bold = .t.
  .TypeText(chr(9)+ "REPORT DATE:")
  .Font.Bold = .f.
  .TypeText(chr(9) + dtoc(p_gamedate))
  .Font.Bold = .t.
  .TypeText(chr(9) + "OPPONENT:")
  .Font.Bold = .f.
  .TypeText(chr(9) + p_visitor)
  do case
    case p_rpt_type = 1    &&playoff round summary
      .Font.Bold = .t.
      .TypeText(chr(9) + "ROUND:")  &&need game in here as well
      .Font.Bold = .f.
      .TypeText(chr(9) + alltrim(str(p_round)))
      .TypeParagraph
    case p_rpt_type = 2    &&playoff game summary
      .Font.Bold = .t.
      .TypeText(chr(9) + "ROUND:")  &&need game in here as well
      .Font.Bold = .f.
      .TypeText(chr(9) + alltrim(str(p_round)))
      .Font.Bold = .t.
      .TypeText("    GAME:  ")  &&need game in here as well
      .Font.Bold = .f.
      .TypeText(alltrim(str(p_gamenum)))
      .TypeParagraph
    otherwise             &&Regular season game so go to the next line
      .TypeParagraph
  endcase 
  *Header fields...line 3
  .Font.Size = 7  &&move down from previous line
  .TypeParagraph
  .Font.Size = 10
  .Font.Bold = .t.
  .TypeText(chr(9)+ "EVENT:")
  .Font.Bold = .f.
  .TypeText(chr(9) + alltrim(p_event))
  .Font.Bold = .t.
  .TypeText(chr(9) + "LOCATION:")
  .Font.Bold = .f.
  .TypeText(chr(9) + alltrim(p_location))
  .Font.Bold = .t.
  .TypeText(chr(9) + "INTENSITY:")
  .Font.Bold = .f.
  if p_intens > 0 then 
    .TypeText(chr(9) + alltrim(str(p_intens)))
  else
    .TypeText(chr(9) + "n/e")
  endif
  .Font.Bold = .t.
  .TypeParagraph
endwith
*add a line
oWord.ActiveDocument.Shapes.AddLine(18, 185, 590, 185).Select  &&BeginX, 
BeginY, EndX, EndY
with oWord.Selection.ShapeRange
  .Line.Style = 5  &&thick between thin
  .Line.Weight = 8
  .LockAnchor = .t.
  .WrapFormat.Type = 5
  .WrapFormat.AllowOverlap = .t.
endwith
oWord.Selection.Collapse(0)
*
with oWord.Selection
  .TypeParagraph
  .TypeParagraph
endwith


I am sure this is more than enough to get you started...
Regards,

Jack Skelley


________________________________________
From: [email protected] [[email protected]] On Behalf Of 
Rafael Copquin [[email protected]]
Sent: Friday, September 25, 2009 10:08 AM
To: [email protected]
Subject: WORD AND AUTOMATION

A client of mine has literally hundreds of Word documents with the Company's 
logo EMBEDDED into the document header. Because of an inherent ignorance in the 
correct use of Word, they did not even consider the possibility of LINKING the 
logo, which would have at least two benefits for them:

1 - lighter files
2 - the possibility of replacing the logo with another one, by simply putting 
the new one in lieu of the old one, but with the same name.

Now, they opened a new branch, with a different logo, and need to use the same 
set of hundreds of documents, but this new logo in the header.

I was thinking of writing a program that would open the old document, somehow 
get rid of the embedded logo and replace it with a link to the new one.

Any ideas on how best to do it? Any code examples?

TIA

Rafael Copquin


--- StripMime Report -- processed MIME parts ---
multipart/alternative
  text/plain (text body -- kept)
  text/html
---

[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/0b957900b2b8194d998a441195b660383886056...@drdsrv03.drdad.thenewarkarena.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to