Discussion Locked

Office Automation Using C

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Can this be done in C?

Sub Main()
Dim oWord As Object
Dim oDoc As Object
Dim oRange As Object
Dim oPara As Object

Set oWord = CreateObject("Word.Application")
With oWord
.WindowState = wdWindowStateMaximize
.Documents.Add
Set oDoc = oWord.ActiveDocument
Set oRange = oDoc.Range
With oRange
.Font.Bold = True
.Font.Italic = True
.Font.Size = 16
.InsertAfter "RunningWord From VB Using Automation"
.InsertParagraphAfter
'Insert a blank paragraph between the two paragraphs
.InsertParagraphAfter
End With

Set oPara = oRange.Paragraphs(3)
With oPara.Range
.Bold = True
.Italic = False
.Font.Size = 12
.InsertAfter "Report Created: "
.Collapse Direction:=wdCollapseEnd
.InsertDateTime DateTimeFormat:="MM-DD-YY HH:MM:SS" End With

.ActiveDocument.SaveAs "D:\Download\autCreateDate.Doc"
.Quit
End With

Set oWord = Nothing
Set oDoc = Nothing
Set oRange = Nothing
Set oPara = Nothing
End Sub

3 replies

by ananthap

I know a guy who once linked MS-Excel 97 with FoxPro 2.6 for DOS to print a particular report.

What he was doing was to use the Excel object model via an "Auto_start" macro in Excel. (Data sent thru a "flat file" and imported ..).

Given thatthe word object model is the same whichever way you interface with it, it should be possible to do it in C using a `system` command.

But I'm not sure that answers your questiion. Why was it posted. Visual Basic code in a C program.

Am I allowed to use Macros? what are the constraints? whats the right answer?

Dnd

by jackofalltech

Thanks for the response. I should have been more specific bu I wasn't sure how close to the char. limit I was. What I want is to be able to perform the same task that that VB code does but do it in plain C (not MFC). In other words, would I create a pointer to the Word object and, if so, how?

This discussion is closed to new replies.