Quantcast
Channel: Word for Developers forum
Viewing all 4350 articles
Browse latest View live

Save As & Open Dialog Window for some documents hangs when custom VSTO plugin is installed

$
0
0

Hello,

I have created a VSTO application which uploads a word document to Document Management Server. The problem is not with this plugin, but after the plugin is installed, for certain documents when user makes some modification to the document and clicks on File -> Save As or File ->Open, the Save As/Open Dialog window, does  not show up and the Word application will be hung (spinning) as it should do if the Save As dialog window would have been shown. The only option is then to kill the WinWord process from Task Manager. When I kill the WinWord process from task manager, I see the Save As Dialog window appear for a split second before the WinWord Process shuts down.

If I uninstall the VSTO application, everything works fine.

Details on the application:

  • Target Framework: .NET Framework 4
  • Platform Target: x86
  • OS (Developer and End User): Windows 7 Enterprise SP1 64 bit
  • Microsoft Office: Microsoft Office Professional Plus 2010 Version: 14.0.6129.5000 (32-bit)

Help!!

Regards,

Yogesh 


Word 2007 Addin to add Watermark image saved as .doc file

$
0
0

I currently have an addin that was developed to work in both Word 2007 and Word 2010 with the assumption the addin would be used on .docx files.  However, it is now required to also work on .doc files but still with Word 2007 and Word 2010.  Although the following code works in both versions of Word, it will only work on .docx files and not .doc files.  On the line:

            Dim shape As Shape = doc.InlineShapes.AddPicture(strWatermarkFile, linkToFile, saveWithDocument, headerfooterRange).ConvertToShape()

I get the Error HRESULT E_FAIL has been returned from a call to a COM component.

My code that works in 2007 on .docx files and not .doc files is:

    Public Shared Function AddWaterMark2007(strWatermarkFile As String)
        Dim app As Application = Globals.ThisAddIn.Application
        Dim doc As Document = Globals.ThisAddIn.Application.ActiveDocument
        Dim headerFooter As HeaderFooter
        Dim hfIndex As WdHeaderFooterIndex = WdHeaderFooterIndex.wdHeaderFooterFirstPage ' WdHeaderFooterIndex.wdHeaderFooterPrimary
        Dim linkToFile As Object = False
        Dim saveWithDocument As Object = True

        If doc.Sections(1).Headers IsNot Nothing Then
            headerFooter = doc.Sections(1).Headers(hfIndex)
        ElseIf doc.Sections(1).Footers IsNot Nothing Then
            headerFooter = doc.Sections(1).Footers(hfIndex)
        Else
            headerFooter = Nothing
        End If

        If headerFooter IsNot Nothing Then

            Dim headerfooterRange As Object = headerFooter.Range
            Dim shape As Shape = doc.InlineShapes.AddPicture(strWatermarkFile, linkToFile, saveWithDocument, headerfooterRange).ConvertToShape()

            shape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue
            shape.WrapFormat.AllowOverlap = -1

            shape.RelativeHorizontalPosition = WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin
            shape.Left = WdShapePosition.wdShapeCenter
            shape.ScaleHeight(1, Microsoft.Office.Core.MsoTriState.msoTrue)

            shape.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin
            shape.Top = WdShapePosition.wdShapeCenter
            shape.ScaleWidth(1, Microsoft.Office.Core.MsoTriState.msoTrue)

            shape.Name = "WordPictureWatermark"
            doc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True

        End If


        app.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument
        app.ActiveWindow.ActivePane.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdPrintView
    End Function

Thanks in advance for any suggestions!

How to retrieve the content in the specific page in Microsoft Word using macro?

$
0
0

Hi , I am trying to write a macro that retrieve the content on the specific page on Microsoft Word document? I want these code put on ThisDocument property, is it a way to do that?

Thanks,

Lin Li

How to access summary or Revisions of two compared word files in vb.net

$
0
0

hi, I want to compare two word files and i successfully did it programmatically  but i want to insert summary results or Revisions(Insertions,deletions,moves,formatting,comments) in database using vb.net.

I used following line of codes to compare the word files but i don't know how to access revisions.please help me thank you.

Public Sub CompareDocument()
        Dim missing As Object = System.Reflection.Missing.Value
        'create a readonly variable of object type and assign it to false.
        Dim readonlyobj As Object = False
        Dim filename As Object = "C:\Users\Admin\Desktop\amit.docx"
        'create a word application object for processing the word file.
        Dim app As Word.Application = New Word.ApplicationClass()
        'create a word document object and open the above file..
        Dim doc As Word.Document = app.Documents.Open(filename, missing, readonlyobj, missing, missing, missing, _
         missing, missing, missing, missing, missing, missing, _
         missing, missing, missing, missing)
        Dim filenm As String = "C:\Users\Admin\Desktop\amit2.docx"
        Dim nm As String = "C:\Users\Admin\Desktop" + "\" & getfilename("amit.docx")
        Dim filesavename As Object = nm
        doc.TrackRevisions = True
        doc.ShowRevisions = True
        doc.PrintRevisions = True
        doc.Compare(filenm, missing, missing, missing, missing, missing, _
        missing, missing)
        doc.Close(missing, missing, missing)
        app.Quit(missing, missing, missing)
    End Sub

 Private Function getfilename(ByVal sfilename As String) As String
        Dim fin As New FileInfo(sfilename)
        Return fin.Name
    End Function



Replace the Textual values of Word table by Colored ovals in C# at the Run time

$
0
0

Hello,

In my working project, I'm trying to replace the cells of Word table that have textual data by colored ovals into the C# code.

The Word table will be generated dynamically at the run time through my code.For example, 

  • replace the value for the cell that has the text A by Red Oval
  • the value for the cell that has the text B by Green Oval
  • and the the value cell that has the text C by Yellow Oval. 

I really cannot figure out how I can do this task

Please if you could help me in that. 

Error: -2147418111, Call was rejected by callee

$
0
0

I have a VB program that creates Word documents automatically. It has worked perfectly fine through prior versions of Windows and Word. We recently switched to Windows 8.1 and Word 2013. When creating a Word document, I get the error message "-2147418111, Call was rejected by callee"

A portion of my code is below:

Imports System
Imports System.IO
Imports System.Text
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Word

Public Class frmCreateDocs
    Public wdObj As Word.Application
    Public wdUnits1 As WdUnits = WdUnits.wdStory
    Public wdBk As WdGoToItem = WdGoToItem.wdGoToBookmark
    Public wdFmt As WdDocumentType = WdDocumentType.wdTypeDocument
    Public wdChar As WdUnits = WdUnits.wdCharacter
    Public wdLine1 As WdUnits = WdUnits.wdLine
    Public wdPara As WdUnits = WdUnits.wdParagraph
    Public wdExt As WdMovementType = WdMovementType.wdExtend

        With wdObj
            DocName = SetTemplate & "Lgl2010.dotx"
            .Documents.Add(Template:=SetTemplate & "Lgl2010.dotx", NewTemplate:=False, DocumentType:=WdDocumentType.wdTypeDocument)
            DocName = SetDir & "TrustAmend.docx"
            .Documents.Open(FileName:=SetDir & "TrustAmend.docx", ReadOnly:=True)
            .Selection.EndKey(wdUnits1, Extend:=wdExt)
            .Selection.Copy()
            .ActiveDocument.Close()
            .Selection.Paste()
        End With

The error seems to occur when the .Selection.Endkey command is run.

Any suggestions?


Don Murray

microsoft word 2010

$
0
0
Good Morning

I have asolutionmadewith VisualStudio2010thatwill insert picturesin MicrosoftWord 2010.I have usedMicrosoftOffice14.0Object Library, as we haveMicrosoftoffice 2010.everythingworks finebut when the company installed lync2013allimplementation walkingwith Worddo not work. withLync 2010there wasno problem.Soto createObject "CreateObject" thereis no problembut itbugsall the time in"visible"and "add"newTemplate. i mean,  when I wanttomake it visibleand open theTemplate.I did someresearchbut without success. Sothe way I'm trying todo this is with"latebinding"exp"Dim oDocas object", "dim  docAppasobject"but difficult when it comes to work with Bookmarks , Sélections ,and page layout.My question is:is  there  anotherway?.Whydoes it workwithLync2010andLync 2013does not work?Issomeonehas alreadyencountered thisproblem ?.- i can not create 2 solutions because i have only word object 14.0 , i mean Microsoft office 2010 but also lync 2013.i hope someone Canhelp me withthisproblem.

Thankyou in advance

Pavel

Error: -2147418111, Call was rejected by callee

$
0
0

I have a VB program that creates Word documents automatically. It has worked perfectly fine through prior versions of Windows and Word. We recently switched to Windows 8.1 and Word 2013. When creating a Word document, I get the error message "-2147418111, Call was rejected by callee"

A portion of my code is below:

Imports System
Imports System.IO
Imports System.Text
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Word

Public Class frmCreateDocs
    Public wdObj As Word.Application
    Public wdUnits1 As WdUnits = WdUnits.wdStory
    Public wdBk As WdGoToItem = WdGoToItem.wdGoToBookmark
    Public wdFmt As WdDocumentType = WdDocumentType.wdTypeDocument
    Public wdChar As WdUnits = WdUnits.wdCharacter
    Public wdLine1 As WdUnits = WdUnits.wdLine
    Public wdPara As WdUnits = WdUnits.wdParagraph
    Public wdExt As WdMovementType = WdMovementType.wdExtend

        With wdObj
            DocName = SetTemplate & "Lgl2010.dotx"
            .Documents.Add(Template:=SetTemplate & "Lgl2010.dotx", NewTemplate:=False, DocumentType:=WdDocumentType.wdTypeDocument)
            DocName = SetDir & "TrustAmend.docx"
            .Documents.Open(FileName:=SetDir & "TrustAmend.docx", ReadOnly:=True)
            .Selection.EndKey(wdUnits1, Extend:=wdExt)
            .Selection.Copy()
            .ActiveDocument.Close()
            .Selection.Paste()
        End With

The error seems to occur when the .Selection.Endkey command is run.

Any suggestions?


Don Murray


Macro to find and replace paragraph in Word 2010

$
0
0
Is that possible to find a paragraph and replace this paragraph with another paragraph in Word 2010 by macro?

Extracting Data from Word Table into Excel (2010 suite and VBA Macro)

$
0
0

Good afternoon and please excuse the interruption.

I am looking to do the following:

I have a 2000+ page Word document that contains a table. The table has 5 Columns (lets say they are named Column1-5 accordingly)

The goal is to export data from the word table and import it into an excel spreadsheet. Here is the twist though. I want the macro to look for a word in Column5, if the word Patent is in there, export that row into excel, if not, dont export it. It needs to scan the entire table and pull out the rows where the content in Column5 has the word Patent (it can be anywhere in that cell)

I came across a VBA code that when placed in Excel and run, will take the table created in word and export it all into excel, which is cool but I feel thats only 80% of what I need it to do.

Sub ImportWordTable()
Dim wdDoc As Object
Dim wdFileName As Variant
Dim TableNo As Integer 'table number in Word
Dim iRow As Long 'row index in Excel
Dim iCol As Integer 'column index in Excel

wdFileName = Application.GetOpenFilename("Word files (*.doc),*.doc", , _"Browse for file containing table to be imported")

If wdFileName = False Then Exit Sub '(user cancelled import file browser)

Set wdDoc = GetObject(wdFileName) 'open Word file

With wdDoc
TableNo = wdDoc.tables.Count
If TableNo = 0 Then
MsgBox "This document contains no tables", _
vbExclamation, "Import Word Table"
ElseIf TableNo > 1 Then
TableNo = InputBox("This Word document contains " & TableNo & " tables." & vbCrLf & _"Enter table number of table to import", "Import Word Table", "1")
End If
With .tables(TableNo)
'copy cell contents from Word table cells to Excel cells
For iRow = 1 To .Rows.Count
For iCol = 1 To .Columns.Count
Cells(iRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text)
Next iCol
Next iRow
End With
End With

Set wdDoc = Nothing

End Sub

I need it to also prompt for any doc or docx file.

Can anyone assist?

How to use DocumentBeforeSaved in Microsoft word in MAC system

$
0
0

Hey guys. 

This code is from:http://stackoverflow.com/questions/24702493/how-to-run-a-macro-in-word-before-save

PrivateWithEvents App As Word.ApplicationPrivateSub Document_Open()Set App = Word.ApplicationEndSubPrivateSub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI AsBoolean, Cancel AsBoolean)
MsgBox("BeforeSave")EndSub

I run this code successfully in Windows. However, when it turns to MAC book it didn't work. Can something tell me why and help me to fix this?

Sincerely,

How to get digital signatures from office 2003 files using code like c# or VB.Net?

$
0
0

Is there a way to get all digital signatures in a MS-Word files from Office 2003. We are having problems trying to get signatures from files that were created with Office 2003. We need help!

We cannot get code in VB.Net or C#, is very difficult.




Open /Copy&Paste Word document content from bytes/file streams to Current Active document.

$
0
0

Hello,

Currently i am saving word document content(including fields,text,pictures etc..) into  a flat file by using filestreams. like this

  var iPersistFile = (System.Runtime.InteropServices.ComTypes.IPersistFile) _WordDocument;
                    string wTempFile = Path.GetTempFileName();
                    iPersistFile.Save(wTempFile, false);

                    byte[] wordDocBytes = File.ReadAllBytes(wTempFile);
                    using (var fWriteStream = new FileStream(filepathName, FileMode.Create, FileAccess.ReadWrite))
                    {
                        fWriteStream.Write(wordDocBytes.ToArray(), 0, wordDocBytes.ToArray().Length);
                        fWriteStream.Close();
                    }

So , now i am able to open that flat file and copy & paste the content to current word document, but here it's opening as like embedded object i.e its getting a box around the data of word content see below image for reference. how can i open that flat file like as normal word document. I used below code to open the document. Any help would be appreciate. i am using win7, with office 2007. 

        DataObject objData = new DataObject();
                 string[] filename = new string[1];
                 filename[0] = _FilePath;
                 objData.SetData(DataFormats.FileDrop, true, filename);
                 Clipboard.SetDataObject(objData, true);

                 _WordDocument.ActiveWindow.Selection.WholeStory();
                 _WordDocument.ActiveWindow.Selection.Paste();

Question about updating Table of Authority

$
0
0

Hi,

I am currently working on inserting Table of Authorities. After I insert table of authorities, I try to apply font size and other formatting properties. Once I apply, due to changes page number it points to are no longer correct. If I try to do TableOfAuthority update then I lose all the formatting.

Is there anyway I could preserve the formatting and also have correct page numbers once update of TableofAuthorities is called ?

Thanks,

Arun

Word 2007 XML Format

$
0
0

Good Afternoon,

I am playing around with VBA and I came across something that I tried doing some time ago. Add a custom XML file into the Word 2007 XML Format and then access it programmatically.

For instance; I have a list that I would like to load into a dropdown ribbon control. If I can create a small XML file with this information then I could read the information from the XML file and load it into the control.

Hope I am being clear.

Gus


Gustavo Miller


Late Binding Word Automation creates a document with an unresponsive Ribbon

$
0
0

I have a .NET ActiveX COM object that is calling Word and adding a template for processing. This template will get some data and then add in a layout template which will create the final document with the data and layout.

When it is all said and done, the Word document has all the data, however, when the user tries to access the ribbon (click on one of the tabs or an item in the visible ribbon), nothing happens (like it is disabled).  You can click into the document itself and if the document has bolded text or something like that the ribbon changes to reflect the changes in font. 

The only way for the ribbon to become responsive is to either minimize and reshow Word or select another application and then back to Word.  This "unlocks" the ribbon and you can interact with it.

I accidently left in a reference to Word 2010 when I was testing something and then the code I have worked.  I went back to late binding and removed the reference to Office 2010 and it does not work even though none of my code has changed.  The Word constants/enums I am using were already locally created and the methods I am using have the either no parameters or the appropriate parameters provided as far as I know.

In the code snippet below, the line "officeApp.ActiveWindow.Activate()" is what worked with early binding to cause the ribbon to be responsive immediately and allow the use to interact with the ribbon with no additional steps.  With late binding nothing seems to work.

Code snippet :

Dim reportDocument As Object = Nothing

Try
      officeApp = GetObject(, "Word.Application")
      usingExistingWord = True
Catch exp As Exception
      'Not Ideal - would prefer not to rely on Exception handle to catch this
      If officeApp Is Nothing Then
            officeApp = CreateObject("Word.Application")
      End If
End Try

Try
      'Open process template
      templateDocument = officeApp.Documents.Add(Template:=ProcessTemplate)
Catch exp As Exception
      Success = False
      If Not usingExistingWord Then
            officeApp = Nothing
            templateDocument = Nothing
      End If

      Throw exp
End Try

If templateDocument Is Nothing Then
      'The process template was not loaded/added properly, abort code
      If Not usingExistingWord Then
            officeApp.Quit()
            officeApp = Nothing
      End If

      Success = False
      Exit Sub
End If

'hide Word while the process template runs its code.
officeApp.Visible = False

Try
      officeApp.Run("RunReport", _parameters, reportDocument)
Catch exp As Exception
      Success = False
      If officeApp IsNot Nothing Then
            If templateDocument IsNot Nothing Then
                  templateDocument.Close(SaveChanges:=False)
                  templateDocument = Nothing
            End If

            If Not usingExistingWord Then
                  officeApp.Quit()
            End If
            officeApp = Nothing
       End If
       Throw exp
End Try
If Success Then
       Try
            If reportDocument IsNot Nothing Then
                 reportDocument.Activate()
            End If

            officeApp.ActiveWindow.Activate()

            officeApp.Activate()

            officeApp.ActiveWindow.ToggleRibbon()
            officeApp.ActiveWindow.ToggleRibbon()

        Catch ex As Exception
            End Try
        End If

        'Done - close the process template
        templateDocument.Close(SaveChanges:=c_wdDoNotSaveChanges)
End If
Thanks in advance for any help you are able to provide!





Shape color

$
0
0

I have the following macro that draws a line in a document. With the document saved as a .doc and I run the macro the line is BLACK. We are starting to save our documents as .docx files. When we save a document as a .docx file and run the following macro the line is now BLUE. How do I revise my macro to default back to BLACK?

Sub AddRevisionBar()
On Error GoTo endthis
For Each aVar In ActiveDocument.Variables
    If aVar.Name = "idx" Then
        num = aVar.Index
        Exit For
    End If
Next aVar

If num = 0 Then
    ActiveDocument.Variables.Add Name:="idx", Value:=0
End If
    idx = ActiveDocument.Variables("idx").Value + 1
    i = Selection.Information(wdVerticalPositionRelativeToPage)
    j = InchesToPoints(InputBox("BAR LENGTH {In Inches}:"))
    ActiveDocument.Shapes.AddLine(562, i, 562, j + i).Name = "vline" & idx
    ActiveDocument.Variables("idx").Value = idx
endthis:
Set aVar = Nothing
End Sub

Referencing a command button

$
0
0

I have a Word (2010) template document which pops up a user form on Open.  The user form solicits info to go into the document and has a button allowing the user to post the info to the document, and then Save and Email it.   Or the user can click another button to just Save the document for editing and emailing later.  So, there is a command button in the document itself allowing the user to Email the document when it is finally ready.  I want to delete or disable the command button in the document if the user chooses to e-mail the document from the user-form.

I can't figure out how to reference the button in the document.  I have tried ActiveDocument.Shapes("btnEmail").delete and ActiveDocument.InlineShapes("btnEmail").delete and .Enabled=False with and without quotes to no avail. In each case I get one or another error message about member not found or property or method not supported.  Shapes.Count returns 0 members, and InLineShapes.Count returns 3 members.  I have tried code to delete every member of the InLineShapes collection, and 3 items are deleted (a couple of horizontal lines and something else), but the command button survives.

Any suggestions?

Thanks,

Peter

Can we use macro to retrieve the version of Microsoft Word version users are using?

$
0
0
Just like the topic says, is there anyway to retrieve the version of Microsoft Word on this computer?

Double space issue in word 2010

$
0
0

Hi,

I am currently converting all my word 97 documents to word 2010.

I need to mail merge the document.

In the development mode of word the double space is present after period (Full stop).

After generating the document through application , the double space is not appearing.

Eg.,.

Before : to.  But 

After Generating: to.But

Thanks.

Viewing all 4350 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>