N
NickP
Hi there,
I had written this in another thread but I guess the title doesn't
help...
I have a class below that is supposed to get the EMF bits from each page
of a Word document, unfortunately
it failes after the first page, but not *all* the time. I have had exactly
the same code working on more than one occasion.
------------
Imports Microsoft.Office.Interop.Word
Public Class PageThumbs
Public Shared Sub enumeratePageThumbs()
Dim opendialog As New OpenFileDialog()
If (opendialog.ShowDialog = DialogResult.OK) Then
Dim app As New Application
Dim doc As Document = app.Documents.Open(opendialog.FileName,
ReadOnly:=True, Visible:=False)
Dim failed As Boolean
Dim activepane As Pane = doc.ActiveWindow.Panes.Item(1)
Dim docpages As Pages = activepane.Pages
Dim pagecount As Integer = docpages.Count()
Dim curpage As Integer
For curpage = 1 To pagecount
Try
Console.WriteLine("Getting emf bits for page '" &
curpage.ToString & "/" & pagecount.ToString & "'.")
Dim emfbits = docpages.Item(curpage).EnhMetaFileBits
'<<This line doesn't always work for pages > 1
Console.WriteLine("Got bits for page.")
Catch ex As Exception
Console.WriteLine("Failed to get bits for page.")
failed = True
MessageBox.Show(ex.ToString)
End Try
Next
If (failed) Then
MessageBox.Show("Failed!")
Else
MessageBox.Show("Succeeded!")
End If
Call doc.Close()
Call app.Quit()
End If
End Sub
End Class
------------
The strange thing is that page 1 *always* works! But the other pages
don't. Very strange, has anyone else experienced this?
BTW I am using Office 2007.
Nick.
I had written this in another thread but I guess the title doesn't
help...
I have a class below that is supposed to get the EMF bits from each page
of a Word document, unfortunately
it failes after the first page, but not *all* the time. I have had exactly
the same code working on more than one occasion.
------------
Imports Microsoft.Office.Interop.Word
Public Class PageThumbs
Public Shared Sub enumeratePageThumbs()
Dim opendialog As New OpenFileDialog()
If (opendialog.ShowDialog = DialogResult.OK) Then
Dim app As New Application
Dim doc As Document = app.Documents.Open(opendialog.FileName,
ReadOnly:=True, Visible:=False)
Dim failed As Boolean
Dim activepane As Pane = doc.ActiveWindow.Panes.Item(1)
Dim docpages As Pages = activepane.Pages
Dim pagecount As Integer = docpages.Count()
Dim curpage As Integer
For curpage = 1 To pagecount
Try
Console.WriteLine("Getting emf bits for page '" &
curpage.ToString & "/" & pagecount.ToString & "'.")
Dim emfbits = docpages.Item(curpage).EnhMetaFileBits
'<<This line doesn't always work for pages > 1
Console.WriteLine("Got bits for page.")
Catch ex As Exception
Console.WriteLine("Failed to get bits for page.")
failed = True
MessageBox.Show(ex.ToString)
End Try
Next
If (failed) Then
MessageBox.Show("Failed!")
Else
MessageBox.Show("Succeeded!")
End If
Call doc.Close()
Call app.Quit()
End If
End Sub
End Class
------------
The strange thing is that page 1 *always* works! But the other pages
don't. Very strange, has anyone else experienced this?
BTW I am using Office 2007.
Nick.