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

Anchoring shapes to a specific range

$
0
0

Hello,

I have fairly complex code that we use to highlight changes in publications. Basically, it adds vertical lines in the left margin based on a currently selected range of text. A bit like the "Track Changes" line, but as shapes.

I have been using this code since Office 1997 without any problems, that is, until Office 2013...

As I said, the code is complex because there are so many factors to be considered... Is the range in a header/footer? Is there a table? What are the "Space Before" paragraph settings? Is HTML spacing on? How wide is the left margin? etc.

However, it seem the problem is this line of code:

        Set myShape = ActiveDocument.Shapes.AddLine(1, 1, 1, 10, rngCurrent.Paragraphs(1).Range)

Word 2013 totally ignores the stuff in brackets. It used to be that the coordinates "1,1,1,10" were relative to "rngCurrent.Paragraphs(1).Range". No longer. Word 2013 ignores the Anchor parameter and uses the coordinates as if they were relative to the page and then proceeds to place the anchor next to the first paragraph that is not in a table on the said page.

How do I get it to anchor "myShape" to "rngCurrent.Paragraphs(1).Range"?

Thank you for any assistance.


App for Office Word: How to add OOXML to a specific point

$
0
0

Hi;

All the examples I've been reading use either current selection on document or Rich Text Content Control to bind a section, then populate it with App for Office API.

What I need to do is add OOXML into a pre-defined section in document. Does Rich Text Box accept OOXML as coercion type?

If not what is my alternative for this type of situation?

Thanks

Spell check using Word COM object

$
0
0

I have built a winform application where I have added a spell check feature using the Word COM object. I have used the code given here

https://msdn.microsoft.com/en-IN/library/ms173188(v=vs.80).aspx

Problem:

When the code reaches last line 

app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);

it abruptly open the word (as a flash) and closes it. Can we close the word silently without user getting to know.


Ankur Chakravarty Hyderabad

Highlight selective words

$
0
0
Looking for macro/vb6/vb.net code to highlight in yellow certain words (as may be preset in an array), if found,  in word 2007 document.

wdUndefined - What is it?

$
0
0

Hello there

 

I recorded a macro to try to get an idea of coding for something, and it has a lot of variables set to wdUndefined.  Looking it up in the help file wasn't so helpful as the best I could get out of it was what it wasn't.  Here's an example of what I've got.

With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)
        .NumberFormat = "%1."
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleUppercaseLetter
        .NumberPosition = InchesToPoints(0.25)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = InchesToPoints(0.5)
        .TabPosition = wdUndefined
        .ResetOnHigher = 0
        .StartAt = 1With .Font
            .Bold = wdUndefined
            .Italic = wdUndefined
            .StrikeThrough = wdUndefined
            .Subscript = wdUndefined
            .Superscript = wdUndefined
            .Shadow = wdUndefined
            .Outline = wdUndefined
            .Emboss = wdUndefined
            .Engrave = wdUndefined
            .AllCaps = wdUndefined
            .Hidden = wdUndefined
            .Underline = wdUndefined
            .Color = wdUndefined
            .Size = wdUndefined
            .Animation = wdUndefined
            .DoubleStrikeThrough = wdUndefined
            .Name = ""EndWith
        .LinkedStyle = ""EndWith

 

I'm trying to figure out what it should (or could) be as what I'm working with doesn't have an equivalent to "whatever it wants to be". 

 

How to bind runtime object datasource to Word Document template in C# Winforms?

$
0
0

I am writing a C# Winforms application that needs to generate Word Document reports from an existing template with content controls. I have went throughhttps://msdn.microsoft.com/en-us/library/ms178805.aspx which describes how to add databinding within the word VSTO environment.

However I cannot find any information on how to bind to Word Document from custom application. Could anyone give some advice? Thanks.


Jake See


Code in Word template is actually updating template rather than new Word doc

$
0
0

I've written some code to take a user form's data and update content controls.  It works fine when testing the template.  It doesn't work when testing in new doc created via the template.  The code executes when new doc is created, the user form is displayed and I'm able to fill the form and submit it, but the template is getting updated rather than the new doc.  I'm sure this is something really basic that I'm missing ... since I seldom create code.  I've attached the code below.

Many thanks in advance,

Chris

Private Sub CommandButton_Update_Click()

    Dim cc As ContentControl
    Dim ccValue(12) As String
    Dim formValue(12) As String

    'collect form values
    formValue(1) = UserForm1.TextBox_ClientName.Value
    formValue(2) = UserForm1.TextBox_SowDate.Value
    formValue(3) = UserForm1.TextBox_ClientProject.Value
    formValue(4) = UserForm1.TextBox_City.Value
    formValue(5) = UserForm1.TextBox_State.Value
    formValue(6) = UserForm1.TextBox_ClientName.Value
    formValue(7) = UserForm1.TextBox_ProjectTitle.Value
    formValue(8) = UserForm1.TextBox_ClientPm.Value
    formValue(9) = UserForm1.TextBox_Bpfl_Pm.Value
    formValue(10) = UserForm1.TextBox_ProjectDate.Value
    formValue(11) = UserForm1.TextBox_ProjectTitle.Value
    formValue(12) = UserForm1.ComboBox_Services.Value
    
    For x = 1 To 12
        Set cc = ThisDocument.ContentControls(x)
        cc.Range.Text = formValue(x)
    Next x
    
    Unload Me

End Sub

Edit image size in table cell of word document

$
0
0

Hi,

I need to be able to resize an image inside the table cell of word document that was pasted from clipboard. See below code, hope someone can point me in the right direction.

// Add table
                    Word.Table _table;
                    Word.Range wrdRng = _document.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    _table = _document.Tables.Add(wrdRng, _trackBar.Maximum , 1, ref oMissing, ref oMissing);
                    _table.AllowAutoFit = false;
                    _table.Rows.Height = 450;

                    var colWidth = _table.Columns[1].Width -20;

                    int index = 0;
                    foreach(Cell _cell in _table.Range.Cells)
                    {

                        _trackBar.Value = index;
                        TrackBar1_Scroll(_trackBar, EventArgs.Empty);
                        _cell.Range.Paste();

                        //Resize picture to fit inside the table cell



                        _cell.Range.InsertAfter("\nComments: ");
                        _cell.Range.Font.Size = 12;
                        index++;
                    }

Thanks,


wesley


Set alignment for textbox - microsoft.office.interop.word

$
0
0

Hi,

I have a program that creates a textbox in all footers of a word document. I set the size of the textbox based on the width and height of pageSetup.

The problem is: when the document have portrait and landscape pages, the textbox alignment is in the center(l want it in the center) only for the portrait pages, so i need to find a way to center the textbox for the landscape pages too.

I can center the textbox using word directly by selecting the textbox, then right click -> more layout options -> set alignment to center

Can i do the same with c# ?

My code for creating the textbox and adding it to the shapes:

using (var pageSetup = ComWrapper.Create(DocAsWordDoc.PageSetup)) { SizeF fontSize = ContentMarkingOfficeUtils.GetStringSize(markingData.Text, markingData.FontName, markingData.FontSize); float width = Math.Abs(pageSetup.Value.PageWidth - 9999999.0) < 0.1 ? defaultWidth : pageSetup.Value.PageWidth; float height = ContentMarkingOfficeUtils.GetTextBoxHeight(fontSize, width);

RectangleF textBox = new RectangleF(0, markingData.Placement == ApplyContentMarkingData.ContentMarkingPlacement.Header ? 0 : (Math.Abs(pageSetup.Value.PageHeight - 9999999.0) < 0.1 ? defaultHeight : pageSetup.Value.PageHeight) - height,width,height); using (var shape =ComWrapper.Create(shapes.Value.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, textBox.Left,textBox.Top, textBox.Width, textBox.Height))) { //here i set the text alignment to what i need(center/left/right) ... } }

Thanks.

Wrong dmCopies member value when triyng to get print job info from DEVMODE after printintg from Word (2003,2007,2010)

$
0
0

We are developing program that monitors print jobs in the Windows system. Notification about print job are received by FindFirstPrinterChangeNotification and FindNextPrinterChangeNotification functions. With FindNextPrinterChangeNotification I'm getting DEVMODE structure (by JOB_NOTIFY_FIELD_DEVMODE parameter). I get wrong dmCopies member value when testing application with Microsoft Word. At first Word was returning only value "1". This is fixed by adding "ForceSetCopyCount" value in the registry (more information herehttp://support.microsoft.com/kb/919736/en-us). After that dmCopies started to show correct copy counts.

But this fix has one bug. I get incorrect results if I print documents in same Word (do not turn off Word application):

In first print job i print 1 copy, second time 2 copies, third time again 1 copy.

In my application i get this info from DEVMODE:

first job copy count = 1, second job copy count = 2, third job copie count = 2.  So, I get last max copie count if I try to set copy to 1.

This applies only for Microsoft Word. Excel, PowerPoint works OK. 

After closing and opening Word application I get correct copy count value for first document. So it seems that Word forgets to reset copy count for 1. This bug appears only if I set copy count from higher to 1, but if I set it from 5 to 3 I'm getting 5 and 3 in dmCopies.

Anyone encountered this problem before?

 

 




What does 'ReadingModePrintedPage' do and how to set it.

$
0
0

I have a problem with Word 2013, which might be related to ReadView. It certainly showed up while we were solving whether of not a document loaded by an instance of Word running as a COM object would open in ReadView or PrintView. Perhaps more on that later, but my immediate  problem is an option which may or may not appear in HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Word\Options as ReadingModePrintedPage. It is present in about half or our QA teams machines, a fellow developer has it on her machine but it isn't on my machine. When this option is present and set to one, our application fails at:

     bShowHiddenText = (pView->SHowHiddenText != VARIANT_FALSE);

with error
      800A11FD - The ShowHiddenText method or property is not available
                         because this command is not available for reading.

If the 'ReadingModePrintedPage' is absent or set to zero, then there is no problem and we get the expected results. This piece of code has run quite happily since Word 97 days.

I can find no reference to to the option or what it does (apart from crash our app), or how to set it. There are only 8 hits on Google and the are all self referential. So can anyone tell me:

1) The purpose of the 'ReadingModePrintedPage' flag.
2) How to set/unset it in Word 2013
3) How to set/unset it via the COM interface.
4) If there is any documentation, where can it be found.

I should point out that our clients are reporting this problem and it will get worse as Word 2013 is rolled out to some 10,000 or so users.  

Any help would be much appreciated.


Oswy


Change how to replace based on captured values in Find's RegEx

$
0
0
I am working on bilingual documents (Arabic-English), The two languages have different directions (RTL and LTR respectively) which makes working with it a bit more challenging.

I am writing a macro to change numbers of the form (x.x) to (x,x), a change in the comma.

now here is the problem, sometimes the two numbers are switched when I do the replace, for example: x.y becomes y,x.

after some debugging it turned out that sometimes this (.) in the first form is an Arabic character and when it is replaced with (,) which is an English one it is causing this change in order.

so I want to do is the following, but I don't know how to translate it to VBA:  

    1- look for a match to the expression ([0-9]{1, }).([0-9]{1, }) 'two numbers with a dot in between
      
    2- if the dot in between is English, replace as follows \1,\2  'no change  
    3- else if it is Arabic, replace as follows \2,\1

Thanks for your help


here is the current version of the macro, it is a recorded macro. I just added the if else statement.

   
Sub fixComma()
'
' fixComma Macro
'
'
   If (Selection.Start <> Selection.End) Then
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.LanguageID = wdEnglishUS
    With Selection.Find
        .Text = "([0-9]).([0-9])"
        .Replacement.Text = "\1,\2"
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With

    Selection.Find.Execute Replace:=wdReplaceAll

    Else
      MsgBox "Nothing is selected, Macro terminated"
    End If
End Sub



Or Maybe I am taking the wrong approach here and I should go through the paragraphs myself and check for a match for the RegEx instead of using Find and Replace ?

Images in RTF documents do not have INCLUDEPICTURE tag

$
0
0

Hi,

We need to convert DOC/DOCX documents to .RTF format because we want to upload it in a system (Client provided application) which only displays RTF files.

The system only recognizes linked images in RTF document and searches for INCLUDEPICTURE tag. When the Text Wrapping for image in document is "In line with text" the Image inside RTF is prefixed with INCLUDEPICTURE tag and displays correctly.

When text wrapping is changed to Tight/Behind the text/In front of text, the image does not display in system because INCLUDEPICTURE tag gets missing from the RTF and the file path of the image is wrapped within shp{} tags.

Please let me know if there a ways we can keep the text wrapping as "Tight/Behind/Front of text" and still get INCLUDEPICTURE tag in the document saved as RTF from MSWORD.

Regards,

Nikhil Chaudhari

[SOLVED] Recording new macro in Word 2010

$
0
0

None of the Word 2010 installations at our site are allowing actions to be performed during macro recording in Word. We select Record Macro and get the "casette" cursor. No actions (like enter text, select text, find text) can be executed. After selecting pause or stop recording, actions are allowed.

the macros are being recorded to normal.docm. the macro Sub is written to normal.docm, but has no contents.

"Activedocument" project gets deleted / error #5981

$
0
0

Dear Forum,

from time to time users here experience the error message #5981 saying: "Could not open macro storage".

This message appears when VBA calls s.th. like "[Application.]Activedocument.FullName".

Looking in the project-explorer in VBA reveals that a project for the current document is missing (see attached screenshot).

To be honest I am kind of confused about this: We did not manage to track down the action that leads to this.

Do you have any idea how the project for the activedocument can be deleted?

Kind regards

Sascha


Range.Text produces unexpected result for image

$
0
0

Hi there,

I am processing a document in a Word Add-In that I have written.  I find that a certain range, which as I found includes a certain image, results in a string with a forward slash character "/" when I print the range.text corresponding to that range.  When I delete the image, the "/" is no longer printed.

I cannot understand why this is happening and it is throwing off the character offsets that I am using.

Thanks for any answers you can provide.

foreach (Paragraph para in document.Paragraphs) {
      file.Write(para.Range.Text);
}
FYI I am using Word 2010, not 2013.


how can i trancefair my masseges and friends account from hotmail to outlook

$
0
0
please tell me 
how can i create my recieved email from my email hotmail fathy_el_shafaie@hotmail also all adress and emails to the new mail outlook fathyelshafaie@outlook.com 
because after i creat outlook mail i lost all recevied mail which i have at hotmail
many thanks

integrating with Office Word from iOS custom application and URL scheme file:///

$
0
0

I am writing an app in iOS (language Objective-C) and try to open a docx file by invoking the method openURL and passing the file location to it as per the scheme "ms-word:ofe|u|<urlofmyfile>" where <urlofmyfile> is a local file in the app such as file:///var/. Word app is saying it cannot open the file as it does not recognize the url. Is there any restriction integrating with Office Word from iOS custom application which pass an URL to a local file located in this app?

The sample provided by the kb: https://msdn.microsoft.com/en-us/library/office/dn911482.aspx refer to URL protocol http or https but nothing about local file location file:///

Any help or guidance would be helfull


cedric

Macro to delete CRLF and PGH in document

$
0
0

I am working on a project where we are taking a Family cookbook written in the 80's, scanning it, and then publishing it digitally back for the family. I am scanning it as an RTF, then converting it into Word, where I will then manipulate it and update it. Problem is, sometimes the scan results in a CF/LF, and sometimes it results in a new PGH at the end of the line.

I know how to write macros in Excel, but am somewhat stumped on how to search for and replace a CR/LF and replace it with a PGH command.  This is important as I need to get the formatting (in this case, bullets) properly placed on the page.

I have never written a macro in Word, and this is a task that will require automation as I have about 200 recipes to edit and format.  Any help here would be appreciated.

get the co-ordinates and dimensions of a selection

$
0
0

I am writing a MS Word add-in using VSTO. I need to get the co-ordinates and dimensions of a selection (usually a content control) in points. This is so I can map object locations on particular pages, as word can only give me page height and width in points.

How can I do this?

Viewing all 4350 articles
Browse latest View live