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

Word 2013 CRASHES on Range.find.Execute

$
0
0

Word 2013 crashes if you invoke range.find.execute with tables having merges cells.

Create a 3x3 table in word document and merge last 2 cells of 3rd column
i.e cells C(row=2, col=3) & C(row=3, col=3)

In Cell(row=3, col=2) , write text "test". So resulting table would look like

________________________
________|_______|________|
________|_______|                |
________|__test__|________|

Now invoke this macro:

Dim rng As range

'Use any of these range setter
'Set rng = ActiveDocument.range(0, 0)
'Set rng = ActiveDocument.Tables(1).range
Set rng = ActiveDocument.Content

With rng.Find
    .Forward = True
    .Wrap = wdFindContinue
    .Execute "test"
End With

Result : CRASH !!. While selection.find.execute doesn't crash.

Is there any workaround for this other than selection.find.execute? What does word use natively for find-replace functionality?

Regards,
Rahul


how can I embed Word editor in a .aspx page?

$
0
0

     This question is about asp.net Web App.Our clientele tendedto edit a word document in the Web page such as creating a new document,writing words,inserting tables and inserting chart and so on.

    By now ,I know how to control the word document by using Microsoft.Office.Interop.Word API .But I don't know how can I embed Word in a web page.

    Beg your help.

    

    


赵召

COM Add-In won't run under Word 2007 on Windows 7

$
0
0

We have several customers who use a Word COM Add-In of ours.

The Add-In has worked fine in the past, but now refuses to start.  It shows un-checked on the "COM Add-Ins" dialog accessed from Word Options, with a message talking about a runtime error during startup.  StartUp Behaviour is 3 and stays as 3.

The Add-In consists of a shim written in C++ and a .NET Assembly written in C#, but it doesn't get as far as the OnConnection in the .NET assembly - I know this because that code writes to the Application Event Log, saying the Add-In is starting up, and there is no such message in the App Event Log.  There are no relevant entries in the Application Event Log, so I'm at a loss as to what the problem is.

This only seems to be a problem with Word 2007 (32 bit) running under Windows 7 (32 or 64 bit).

Issue converting from RTF to docx and doc.

$
0
0

Hi

I am converting the RTF file to docx and doc by using SaveAs.

But for some files we are getting COM Exception :

System.Runtime.InteropServices.COMException (0x800A1554): A file error has occurred.
 (Convert9-5b4b6755-75a9-4229-a21a-916f...)
   at Microsoft.Office.Interop.Word.DocumentClass.SaveAs(Object& FileName, Object& FileFormat, Object& LockComments, Object& Password, Object& AddToRecentFiles, Object& WritePassword, Object& ReadOnlyRecommended, Object& EmbedTrueTypeFonts, Object& SaveNativePictureFormat, Object& SaveFormsData, Object& SaveAsAOCELetter, Object& Encoding, Object& InsertLineBreaks, Object& AllowSubstitutions, Object& LineEnding, Object& AddBiDiMarks)

Please help to solve this issue.

Thanks

Paparaju

Getting a Compile error in hidden module after upgrade to Windows 7

$
0
0
We have had a system in place for ten years where we have a file share that's storing Word templates. A central repository holds submitted documents from users which have been created from the templates (.dot,.dotm's) on their machines, and they are stored in this repository in aggregate. These templates contain macros; we are using the WindowSelectionChange event to monitor and control places in the template where we have custom bookmarks. If they click in a bookmark they get a popup dialog to control what they cna enter in to that area of the document. There are receivers who open and edit the files for eventual release. Many of these documents, when opened by the receivers and clicked on in the specially created bookmark areas, throw an error "Compile error in hidden module:ThisApplication. This error commonly occurs when code is incompatible with the version, platform or architecture of this application. Click 'Help' information on how to correct this error." The  WindowSelectionChange event is in the ThisApplication class of the templates. On opening or doing a New on a template on the share before opening one of these documents, we are able to get to the particular field though this error is thrown also in this case.

Value does not fall within the expected range. Microsoft.Office.Interop.Word

$
0
0

Hi, I have already asked this question on MSDN here, but didn't find any solution! 

starting new thread! 

I am having following exception in my project having Microsoft Interops, Com Ad in for Office, When assigning

fldTemp.Result.Font = currRange.Font;
//where currRange is instance of Word.Range 
//and   fldTemp is instance of Word.Field ;

System.ArgumentException: Value does not fall within the expected range.

   at Microsoft.Office.Interop.Word.Range.set_Font(Font prop)
   at xxx.yyy.ThisIsMyFun(args)

same piece of code running on some machines!

what's wrong? 

Kind regards

Restricted Editing inside Rich Text content control in Word allows only a single character to be edited since KB2863926

$
0
0

we have a rich text content control that allows only a single character to be entered, prior to the KB listed above, the content control could handle more content.  

Office 2010 Service Pack 1

This is very easy to reproduce.  Create a new document, add a rich text content control, restrict editing, allow "No Changes (Read Only)" except within the control control allow "Everyone" to edit.  Start Enforcing Protecting. Only a single character will be allowed.

If the KB listed in the title is removed then the editing works properly.


How to add header with text aligned both in the left and right margin, on the same row?

$
0
0

Hi, i have been trying to find information on how to add a header in Ms Word programmatically with the text aligned both in the left and right side of the document.

The application I´m developing is supposed to add a header programmatically when Printing a document. As for the text in the header, I want to add a number, a title and the name of the document on the left side, and the page number, date and time of print on the right side.

I have no problem doing this with the text aligned all to the left or right, but I´m unable to find information on how to do it with the text aligned both left and right on the same rows.

The documents that are printed are in .doc and .docx format. So Word 2003 through 2013.

I am most grateful for any help i can get to make this work.


Saving Word document

$
0
0

I would like to save a Word document according to the Word installed version;

In case it is Word 2003 (appropriate version number is 11), with DOC extension.
In case the Word version is higer than 2003, with DOCX extension.

The difference is reflected in the second argument sent to the SaveAS method:

object fileFormat =GraphDocsSettings.Default.WordInstalledVersion>11.0?WdSaveFormat.wdFormatXMLDocument :WdSaveFormat.wdFormatDocument;

wordDoc.SaveAs(ref outputFile, fileFormat,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);

However, When using Interop.Word 11.0 I get the following error:

Microsoft.Office.Interop.Word.WDSaveFormat does not contain a definition for wdFormatXMLDocument.

Any ideas?

Table Row Height

$
0
0

I have a Word Document of tables that I've created programmatically (using Interop). The default is I'm not specifying a row height. However, when I copy and paste these tables into Microsoft Publisher (2010), the table row spacing becomes excessive.

So, I've resorted to specifying a "Fixed Row Height" of .17" for each row height such as:

mCurrentTable.Cell(mCurrentTableRow, column).Range.ParagraphFormat.LineSpacing = 12.0f;

mCurrentTable.Cell(mCurrentTableRow, column).Range.ParagraphFormat.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceExactly;


Now, when I copy and paste the table, it looks fine in Publisher.

But, my problem is that not all table rows are one line of text. Programmatically, how do I either:

1) Determine the row height (prior to setting an Exact Line Spacing) so that I can use this line spacing for an Exact measurement.

2) Determine part of the text in a row isn't visible if I set the LineSpacing to a fixed height.

In short, how do I specify a fixed row height based on how many lines of text are visible in the row?


Detecting if any change was made in a bookmark Range

$
0
0

Hi,

I would like to detect if any change has been made inside a bookmark range.

I have tried comparing the WordOpenXML against each other, however there's always small changes to the rsid values irrepective of any changes made to the actual content

ie w:rsidP & w:rsidRDefault

Apparently such values are dynamically generated behind the scenes and used for version control.

The closest I can to detecting if a change was made is counting how many elements are in the range

ie bookmark.range.End - bookmark.range.Start

This covers most scenarios but I would still like to detect pure formatting changes and the like. Any suggestions?

how can I operate Charts in word ?

$
0
0

At first I created a Word document like that :

Then I use the Microsoft.Office.Interop.Word API to change the data of the Charts dynamicaly like that:

......

Microsoft.Office.Interop.Word.Chart sh = (Chart)wordapp.Selection.InlineShapes[1].OLEFormat.Object;

...

for(...){

       sh.Application.DataSheet.Cells[x,x] = ......;

}

Questions:

1.I think this method is too verbose.Can I do this in any other way?

2.There was a strange problem:I can operate The Microsoft Graph Chart .But I don't know how to operate the other type of charts.How many types of charts in Word? And how Can I change the data of them?

Thank you very much.



赵召

C# Updating Fields not working,

$
0
0

Hi, 

i'm using C# and Word 2007. I have a document (58 Pages) and a custom table of content (table with 3 columns, last column always has PageRef to Bookmark).

At the dot line (see below) i tried

  • activeDoc.Fields.Update();
  • activeDoc.Fields.Update in separate Task (parallel)
  • foreach field in activeDoc.Fields and field.update
  • foreach field in activeDoc.Fields and field.update in separate task
  • lots of Thread.Sleep

totally confused by the results

  • sometimes no field is updated
  • sometimes the first field is updated and all the other fields have the value of the first field
  • sometimes the first two fields are updated and all other fields have the value of the last updated field
  • sometimes half of the fields are updated, the other fields have the value of the last updated field (How many fields are updated depends on the milliseconds in the Thread.Sleep...)

This behavior makes totally no sense to me. It seems that there is something done asynchronous. If i debug my steps, all fields are updated correctly.

Does anybody has similar experiences?

Does anybody can explain, why just Fields.Update and SaveAs is not working and why i need a lot of threads and Thread.Sleeps???

I just want update all fields. Here is my base code

var application = new Microsoft.Office.Interop.Word.Application();
application.Visible = false;
try
{
    var activeDoc = application.Documents.Open(fileName);

.....................................

    activeDoc.SaveAs(Path.Combine(filePath, fileNameWoExt + "a.docx"));
}
finally
{
    application.Quit();
}


UPDATE:

I just realized something very interesting. i checked the word option to recalculate fields on print preview. i opened my document in word, all fields are not updated (Every Page was 0). i opened print preview and the first field was updated and all the other fields had the same value as the first.

So maybe it is no development problem...

i just use PAGEREF-Fields...


The remote procedure call failed. (Exception from HRESULT: 0x800706BE) while trying to use WORD 2010 in VB.NET.

$
0
0

Hi,

I am getting the The remote procedure call failed. (Exception from HRESULT: 0x800706BE) while trying to use WORD 2010 in VB.NET. The functionality we are trying to achieve is creating a single word file from 9 different files (1.docx; 2.doc etc). This is occuring only on Windows 7 machine. Below is the code snippet i am using. I tried to debug the issue but the error is coming up from docO.Close(False) at different instances like sometimes in loop 5, sometimes in loop 8 etc. The version of interop.word used is 14.0.0.0

Dim oApp As Word.Application
        Dim docI As Word.Document
        Dim docO As Word.Document
        Dim arrayCount As Integer
        Dim txtFilename As String
        txtFilename = Mid(FileOut, 9)

oApp = CreateObject("Word.Application")

        docI = oApp.Documents.Add()
        docI.Select()

        Dim dRan As Word.Range = docI.Range(Start:=0, End:=0)

        For Count = 1 To I - 1
                docO = oApp.Documents.Open(i & ".docx")
                docO.Content.Copy()
                docO = oApp.ActiveDocument
                dRan = docI.Content 'reference to all text in doc
                dRan.Collapse(Word.WdCollapseDirection.wdCollapseEnd) 'move to a point after all the text
                dRan.Paste() 'paste at the end of the doc
                My.Computer.Clipboard.Clear() 'save memory, speed things up
                If arrayCount <> I - 1 Then
                    dRan = docI.Content
                    dRan.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
                    docI.Sections.Add()
                End If
                dRan = Nothing
                docO.Close(False)
                docO = Nothing
            Next

How to reference SharePoint Workflow task in MS Word 2010?

$
0
0

Hello,

Here is my challenge:
There is a workflow that is running in Sharepoint 2010 and associated with Word 2010 document. Once the document is opened the user can click on the button within Word "Open this Task". Once it is clicked the popup window appears that displays InfoPath form from the workflow.

What I need to do is to:

1. Check to see if there is workflow task is pending for any given document

2. If it is pending on Close event I'd like to launch that InfoPath form so user is forced to complete the tasks

3. If workflow task is not pending the user closes the Word file.

Any help is appreciated.
Thank you.


vlad


Use Visual Studio 2010 Express (VB) application to spell check a list of words (English and French).

$
0
0

Hi,

I have a list of words which I need to spell check - firstly against an English dictionary and then the ones that fail this check against a French dictionary.

I am using Word 2007 to do the English spell check

Dim Spelling_checker As New Object()
Spelling_checker = CreateObject("Word.Application")
If Spelling_checker.CheckSpelling(word) Then
       'Passed
Else
       'Failed
       'Check French Dictionary
end if

To do the French spell check i will need to change the language in Word to French by VB code.

Is this possible or is there a better way of doing this?

Thank You.

$whatisthis$

$
0
0

In a Microsoft Word 2010 document I am working with there are these tag looking items with dollar sign in front and back.

When selecting them there isn't any context information so I have no idea what they are or how to create my own which is what I need to do because the code I am working with uses these' tags'.

What are they?

Word VBA to search and replace using wildcards

$
0
0

I would like to have a routine that will search (within "StartRange") for paragraph mark, any number, period, space, any capital letter and then replace that with paragraph mark, the original number, period, space, (Original), space, and the original capital letter.

Ex.:

^p
5. The...

would be replaced with

^p
5. (Original) The...

I started with the following (without limiting the wildcards to letters or numbers), but it does not find the matching patterns (I assume my syntax is off):

Dim StartRange As Word.Range
Set StartRange = Selection.Range
StartRange.Find.Execute FindText:="^p[*]. [*]", ReplaceWith:="^p[*]. (Original) [*]", Replace:=wdReplaceAll

I tried variations of the above - it does work with FindText:="^p5. T", ReplaceWith:="^p5. (Original) T", but not with any wildcard values I tried: *, #, 0-9, A-Z, etc., with and without brackets.  What is the proper syntax for using wildcards in this fashion?

Any help greatly appreciated!

Loop/ repeat a macro through whole document

$
0
0

Greetings,

I got a little side project of sorting through some really long Word documents (doing it manually is not an option) and then mining the relevant data and moving it in an organized way into a table/ excell where it could be sorted in different ways.

the data i have is luckily almost always organized in chunks that are 1 sentence long, and start with the same key-words that I can search.

what I would like to do is basically: 1. search the whole document for a specific keyword (fx: 'year') 2. select the keyword 3. expand the selection to the whole sentence, or expand the selection until a different keyword. 4. then i could copy-paste a huge chunk of info into fx. one column with relatively few errors that I will need to manually correct - and then move on to different keywords.

It should be really simple I think, but using the following stops after highlighting 1 sentence:

Sub Makro1()

With Selection
.Expand Unit:=wdSentence
End With

End Sub


any nudge in the right direction would be appreciated!

How can i find the Repeating section content controls from word document

$
0
0

I am using vb.net and office 2013.

I am writing logic to show the data in word template.Please find that :  Word Template.

In below of CARRIER INFORMATIONsection (find in word template)  ...i have to loop through the data. But i I am able to print the data in first line only.

Because first line has xml nodes. I need to print other lines as well. 

When i google …i came to know that using repeater section ...i can print.

Let me know is this possible to printing the lines using repeater section.

I am able to find the Custom XML Nodes using below code.

   For Each XMlnode As Word.ContentControl In wordDoc.ContentControls

       Dim basename As String = XMlnode.XMLMapping.CustomXMLNode.BaseName.ToString()         Next

But i am unable to find Repeating section content controls. in Word Document (Office 2013).

What property i have to use to find that.

I have seen in google. i got code using VBA  : VBA- Link

Can i have a code snippet in vb.net. 

Thanks,

Kavitha


Viewing all 4350 articles
Browse latest View live


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