John -
I am exporting through VBA. I am having a intermittant error with the
"Remote Server" being unavailable, - error 462; but I am close.
If you are interested - here is my code so far:
Option Explicit
Dim appWord As Word.Application
Sub WhoDoesWhatReportbyCode()
Dim R As Resource ' Resource object used in For Each loop
Dim Rname As String ' Resource name
Dim RID As Long ' Resource ID
Dim txtReportBody As String
Dim aAssign As Assignment
Dim txtResourceInfo As String
Dim strReportTitle As String
Dim txtReportDetails As String
Dim appWordDoc As Word.Document
'Dim appWordRng As Word.Range
RID = 0
Application.StatusBar = "Currently compiling resource information."
'Loop through the resources in the project and then each assignment for each
'of the resources. For each Assignment that is not finished gather data and
'place it into a variable along with the same infor from the other
assignments.
For Each R In ActiveProject.Resources
txtReportBody = ""
txtResourceInfo = R.ID & vbTab & R.Name & vbCrLf
For Each aAssign In R.Assignments
If aAssign.ActualFinish = "NA" Then
With aAssign
'This next part creates the details of the report
txtReportBody = txtReportBody & vbTab & .TaskID & vbTab
& _
.TaskName & vbTab & Format(.Start, "mm/dd/yyyy") & vbTab
& _
Format(.Finish, "mm/dd/yyyy") & vbCrLf
End With
End If
Next aAssign
txtResourceInfo = txtResourceInfo & txtReportBody & "~~"
txtReportDetails = txtReportDetails & txtResourceInfo & vbCrLf
Next R
'Open Word
Err.Number = 0
On Error GoTo NotLoaded
Set appWord = GetObject(, "Word.Application.8")
NotLoaded:
If Err.Number = 429 Then
Set appWord = CreateObject("Word.Application.8")
Debug.Print Err.Number
End If
appWord.Visible = True
Debug.Print Err.Number
'On Error GoTo 0
'Place in Report
On Error Resume Next
appWord.Documents.Add
With appWord.ActiveDocument
Selection.InsertAfter txtReportDetails
If Err.Number = 462 Then
CloseWordObject
MsgBox "Please run report again. If this happens more than" _
& vbCrLf & "once, please close out of Project before" _
& vbCrLf & "trying again.", , "Issues with running report"
End If
End With
Application.StatusBar = "Currently formatting report"
appWord.ScreenRefresh
appWord.Activate
FormatWord
appWord.ScreenRefresh
Application.StatusBar = ""
'Handle Errors Gracefully
Exit_EH:
Exit Sub
EH:
If Err.Number = 462 Then
CloseWordObject
MsgBox "Please run report again. If this happens more than" _
& vbCrLf & "once, please close out of Project before" _
& vbCrLf & "trying again.", , "Issues with running report"
Else
MsgBox Err.Number & ": " & Err.Description
Resume Exit_EH
End If
End Sub
Sub FormatWord()
Dim strReportTitle As String
Dim dtmReportDate As String
Dim appWordDoc As Word.Document
'Format Report Title
dtmReportDate = Now()
strReportTitle = "Who Does What Report" & vbCrLf & dtmReportDate
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InsertBefore
strReportTitle
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.ParagraphFor
mat.Alignment = wdAlignParagraphCenter
'Set Tabs so the table will format nicely
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(0.5), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(1), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(4.5), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(5.5), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
'Convert the text to a table
Selection.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=5, _
AutoFitBehavior:=wdAutoFitContent
With Selection.Tables(1)
.Style = "Table Grid"
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.Rows.AllowBreakAcrossPages = False
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
'Format the page breaks in the Word Document
With appWord.ActiveDocument
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "~~"
End With
While Selection.Find.Execute
Selection.SelectRow
Selection.Rows.Delete
Selection.InsertBreak Type:=wdPageBreak
Wend
Selection.TypeBackspace
Selection.Delete Unit:=wdCharacter, Count:=1
End With
'Format the Table
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdCell
Selection.Rows.HeadingFormat = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Cells.Merge
Selection.Font.Bold = wdToggle
Dim i As Integer
For i = 1 To ActiveDocument.Tables.Count
Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1
Selection.MoveRight Unit:=wdCell
Selection.Rows.HeadingFormat = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Cells.Merge
Selection.Font.Bold = wdToggle
Next i
Selection.Font.Bold = wdToggle
Selection.HomeKey Unit:=wdStory
Application.ActiveProject.Activate
'MsgBox "Report has finished.", , "Who Does What Report"
'appWord.Activate
End Sub
Private Sub CloseWordObject()
If TypeName(appWord) = "Application" Then
appWord.Quit SaveChanges:=wdDoNotSaveChanges
Set appWord = Nothing
End If
End Sub
--
Dawn Crosier
"Education Lasts a Lifetime"
This message was sent to a newsgroup. Please post back to the newsgroup so
all may follow the thread.