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

Word displays Courier, only. ?

$
0
0

All of a sudden, I am editing only in Courier New, not so easy on the eyes.

I am using Word 2010 on Win10.

Debugging as follows:

Set the default font to Cambria. No change.

I Repaired Office.

I Replaced Normal.dotm with a copy from another machine.

I Checked Excel. All fonts are available to Excel and other Office programs.

I copied a document from Word, pasted it into WordPad and selected the desired font Cambria. Wordpad displays the text in Cambria.

Word prints properly, in the desired font. The correct fonts show up in the Print preview.

I was looking at the pasted in text above in Courier in Word, but I see it here as Cambria. This text that I'm typing now I'm seeing in Courier ... So is the Chrome browser impinging on Word somehow?


peter n roth - http://PNR1.com, Maybe some useful stuff


Where I can get user custom comparison settings for Word 2010?

$
0
0
Hi all,

For word comparison API I want to pass comparison settings that user customized in native Word Compare dialog. I noticed that for Word 2013 and 2016 it is written to registry, but I dont know where I can get this settings for Word 2010. VSTO does not provide anything for that.

So, the question iswhere I can get user custom comparison settings for Word 2010?

Thanks.

Calculate the page numbers of all Word documents in a folder via vba

$
0
0

Hi,

I want to calculate the page numbers of all Word documents in a folder using VBA.

Here is the code , but I don't know why it returns wrong page numbers when running.

Who can tell me what's wrong with my code? Thank you!

Sub GetAllPageNumbers()
    Dim objWordApplication As Word.Application
    Dim nPageNumber As Integer
    Dim objFile As Variant
    Dim objFileSystem As Object
    Dim objFolders As Object
    
    Set objWordApplication = New Word.Application
    Set objFileSystem = CreateObject("scripting.filesystemobject")
    Set objFolders = objFileSystem.getfolder("E:\Temp")
    
    For Each objFile In objFolders.Files
        objWordApplication.Documents.Open (objFile)
        nPageNumber = nPageNumber + objWordApplication.ActiveDocument.BuiltinDocumentProperties(wdPropertyPages)
        objWordApplication.ActiveDocument.Close (False)
    Next objFile
    
    MsgBox nPageNumber    
    Set objFile = Nothing
    Set objFileSystem = Nothing
    Set objFolders = Nothing
    Set objWordApplication = Nothing
End Sub


Issue with OLE object of MS Word 2016. It is not saving the document and giving error.

$
0
0

We are creating OLE object of MS Word using following code: 

Type objClassType = Type.GetTypeFromProgID("Word.Basic");
object obj =  Activator.CreateInstance(objClassType);       
return obj;

Now when we try to use FileSaveAs() command for the above object it gives error "The FileSaveAs is not available because a document window is not active."

Document window is open and active. It is working fine with office 2013. This is only happening with office 2016. 

Any help is deeply appreciated.

Regards



Lists in MS Word 2016 not converting properly to list HTML tags

$
0
0

I am working on a Word add-in that uses HTML to display the document on Word. If I make a list using Word's list functionality and then save it using the Word add-in, it doesn't get saved properly. The HTML code of the list will be something like this:

<p  class="MsoListParagraph">List item 1</p>

<p  class="MsoListParagraph">List item 2</p>

So as you can see, it doesn't use HTML's <li> tag for lists. I assume this is the default behaviour of Word 2016, at least for now. So is this an already known bug? And any suggestions on how to get this to use <li> tags?

PS: I have tried using regex to fix this. But the problem is that sometimes the class MsoListParagraph gets appended with something else. And when saving with Word 365 there's an additional bullet symbol inserted using the Symbol font.


Create custom heading in MS Word with PowerShell

$
0
0

Hi, thanks in advance for any and all help.

I'm creating a Word document using Powershell, it all works just fine except I'd like to have a multi-level table of contents like

1. Heading level one

1.1 Heading level two 

1.1.1 Heading level three

and so on... I can achieve this editing word, but I can't find a style(s) using PowerShell.

Thanks again G.


Thanks in advance Gerald

changing paragraph alignment

$
0
0

I am inserting paragraphs into a Word document from a VSTO Word addin.  Click a button on the ribbon, the addin inserts the paragraphs into the document. Problem is, I cannot change the paragraph alignment from one paragraph to the next. All paragraphs are Center aligned. I want the first two to be centered. Then the 3rd and 4th paragraphs to be aligned to the left.  How to do this?

here is my code.  thanks,

      {
        InteropWord.Paragraph para1 = doc.Content.Paragraphs.Add(ref missing);
        object styleHeading1 = "Heading 1";
        para1.Range.set_Style(ref styleHeading1);
        para1.Range.Text = "Invoice";
        para1.Range.ParagraphFormat.Alignment = InteropWord.WdParagraphAlignment.wdAlignParagraphCenter;
        para1.Range.InsertParagraphAfter();
      }

      {
        InteropWord.Paragraph para1 = doc.Content.Paragraphs.Add(ref missing);
        para1.Range.Text = DateTime.Now.ToString("MMMM d, yyyy");
        para1.Range.Font.Size = 14;
        para1.Range.ParagraphFormat.Alignment = InteropWord.WdParagraphAlignment.wdAlignParagraphCenter;
        para1.Range.InsertParagraphAfter();
      }

      {
        InteropWord.Paragraph para1 = doc.Content.Paragraphs.Add(ref missing);
        para1.Range.ParagraphFormat.Alignment = InteropWord.WdParagraphAlignment.wdAlignParagraphLeft;

        var pt = Application.InchesToPoints(4.25f);
        para1.Range.Paragraphs.TabStops.Add(pt, InteropWord.WdTabAlignment.wdAlignTabLeft);
        para1.Range.Font.Size = 12;
        para1.Range.Text = "Company name, LLC" + "\t" + "Invoice #: C8504" + "\v" +"P.O. BOX 99" + "\v" +"Town, NJ  zip";
        para1.Range.InsertParagraphAfter();
      }

      {
        InteropWord.Paragraph para1 = doc.Content.Paragraphs.Add(ref missing);
        para1.Range.ParagraphFormat.Alignment = InteropWord.WdParagraphAlignment.wdAlignParagraphLeft;
        para1.Range.Font.Size = 12;
        para1.Range.Text = "Bill to:" + "\v" + "Company" + "\v" + "IT Department" + "\v" +"street address" + "\v" +"city, state  zip";
        para1.Range.InsertParagraphAfter();
      }

Printing to Word from Infopath

$
0
0

Since custom xml is no longer supported by Word 2010, it would appear I cannot use the feature of Infopath that allows printing via Word by using xsl and a Word template with XML tags.

What is the alternative to this? Or is there a workaround?

Thanks in advance


Server hanging out while opening the word object, it is unable to open the word object. but in my devlopment environment, it working fine

$
0
0

                 Microsoft.Office.Interop.Word.Application objWord = new Application();
                WriteEventLog("created word object", "Created new word object");
                    object missing = System.Reflection.Missing.Value;
                    object readOnly = false;
                    object isVisible = false;
                    object fltDocFormat = 10;
                    
                   
                    
                   objWord.Documents.Open(ref uploadedFile, ref readOnly, ref missing, ref missing, ref missing, ref missing,
                   ref missing, ref  missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing,
                   ref missing, ref missing);
                    WriteEventLog("Opened doc", "Opened doc");
                    //Do the background activity

                    objWord.Visible = false;
                   
                   
                    Microsoft.Office.Interop.Word.Document oDoc = objWord.ActiveDocument;
                    WriteEventLog("Created document object", "Created document object");
                    oDoc.SaveAs(ref htmlFile, ref fltDocFormat, 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);

 

Server is not responding anything at  below line.

objWord.Documents.Open(ref uploadedFile, ref readOnly, ref missing, ref missing, ref missing, ref missing,
                   ref missing, ref  missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing,
                   ref missing, ref missing);
where as it is working fine in my local dev environment, some one please help me, it is high priority work item for me

Rename styles in Word document

$
0
0

Hi there

I have been trying to rename styles in a bunch of Word documents but am kind of stuck as NameLocal is read only.

As a workaround, I vaguely thought of duplicating the style to be replaced, then apply the duplicate to all instances and finally delete the original style. But then I didn't find out how to duplicate a style...

The only solution I can think of right now would be:

  1. Create all new styles manually in a separate document, kind of master document.
  2. Copy them to each of the documents to be modified.
  3. Find out in every document if the style to be "renamed" is in use, and if so, apply the new style instead (I have a table with pairs of old and new style names, of course).
  4. Delete the style that has now become obsolete.

Does somebody know any shorter way to do this?

By the way, we're talking about C#, VSTO and Office 2010 here. Office 2013 would be possible too, if that makes a difference.

Kind regards, and thanks in advance for any helpful suggestions and thoughts.

Nora

MS Word Hyperlinks - Cannot open specified file

$
0
0
Microsoft Word hyperlinks give message "Cannot open specified File"  The URL has been validated by copy/paste into browser and it works fine.  the links are to PDF docs in a folder on a website.  JPG and other files in the same folder link fine from MS Word, but not PDF's.  Same website using a different subfolder work.  see example:
works as hyperlink in word: http://www.nastad.org/docs/014619_Statement%20of%20Urgency.pdf
does not work as hyperlink in word: http://www.nastad.org/files/014619_Statement%20of%20Urgency.pdf

I really need help! (Macro for Word)

$
0
0

Hello.

I happen to work as a Structural Engineer at a somewhat new office and we make structural evaluations for new and old projects. Thing is for each project we have to deliver a report, wich includes having several images (sometimes a lot of them) in the document. I found a macro for adding all the pitures, found one for changing the size and made one (almost didn't believe it myself) for giving them a certain style.

Here comes the problem...

I need to add a picture on top of those pictures i already added, at a certain position and with a certain size. If anyone could help me with this it'd be great. I have a report of almost 400 pictures to make right now!

Replace smart (curly) quotes with straight quotes

$
0
0

Thanks to your help. I have developed VSTO addin for my users that performs small changes like remove empty spaces etc.

Now i need to add new functionality. like 

 Find ‘ (smart apostrophe), replace ' (dumb apostrophe) and find “ (smart quotes), replace " (dumb quotes).

I can't find the documentation on how to do it in c# with Word.Range or Word.Application.ActiveDocument 

Can anyone point me in the right direction?

Thank you.


VB.NET MS-WORD Number List with Character Indents

$
0
0

So it has been a long time since I have attempted to do any word automation but long story short, I need to create a work document that includes a list. The first level being numbers and the second being letters, basically mimicking the out of the box default numbering format but can't quite get it figured out.

The code I have so far just continues the numeric pattern on indent.

Here is the code I have so far and a screen capture of what I need. Thanks

Public NotInheritable Class Utilities
    Public Shared Sub CreateDocument()
        'Local Variable Declaration
        Dim application As New Microsoft.Office.Interop.Word.Application
        Dim document As Microsoft.Office.Interop.Word.Document
        Dim range As Microsoft.Office.Interop.Word.Range

        application.Visible = True

        'Add a new document
        document = application.Documents.Add()

        'Add Header and Footer
        For Each Item As Microsoft.Office.Interop.Word.Section In document.Sections
            'Header
            Dim header As Microsoft.Office.Interop.Word.Range = Item.Headers(Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
            header.Fields.Add(header, Microsoft.Office.Interop.Word.WdFieldType.wdFieldPage)
            header.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter
            header.Text = "Header"
            header.Font.Name = "Arial"
            header.Font.Size = 10.0
            header.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorRed

            'Footer
            Dim footer As Microsoft.Office.Interop.Word.Range = Item.Footers(Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
            footer.Fields.Add(footer, Microsoft.Office.Interop.Word.WdFieldType.wdFieldPage)
            footer.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter
            footer.Text = "Footer"
            footer.Font.Name = "Arial"
            footer.Font.Size = 10.0
            footer.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorRed
        Next

        'Setup Default Range
        range = document.Range()
        range.Style = document.Styles("No Spacing")
        range.Font.Name = "Arial"
        range.Font.Size = 10.0
        range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlack

        range.Text = "Line 1" & vbCrLf
        range.Text &= "Line 2" & vbCrLf & vbCrLf

        Dim paragraph As Microsoft.Office.Interop.Word.Paragraph = range.Paragraphs.Add
        paragraph.Range.Text = "First Numbered Line:"
        paragraph.Range.ListFormat.ApplyNumberDefault(Microsoft.Office.Interop.Word.WdDefaultListBehavior.wdWord10ListBehavior)
        paragraph.Outdent()

        Dim list = paragraph.Range.ListFormat.ListTemplate.ListLevels(1).NumberStyle = Microsoft.Office.Interop.Word.WdListNumberStyle.wdListNumberStyleLowercaseLetter

        paragraph.Range.Paragraphs.Add()
        paragraph.Range.Paragraphs(1).Range.Text = "Second Character Line"
        paragraph.Range.Paragraphs(1).Range.ListFormat.ApplyListTemplate(document.ListTemplates(1), True, list)
        paragraph.Range.Paragraphs(1).Indent()

        paragraph.Range.InsertParagraphAfter()
    End Sub
End Class



How to arrange or accept comments or revisions by date or time order?

$
0
0

Hi,

I have 2 questions. Please bear with me.

Question 1: How to arrange revisions by date or time?

I know there is the "Reviewing Pane", telling when a revision is made. But the date or time showing there is not sorted in time order. Instead, all revisions are put in an order as they show in the document.

Now is there a way to arrange  revisions in time order?

Question 2: How to accept all revisions made in a particular time?

Say, I want to accept all revisions made in a particular range of the time, like in one day. 

Any way to do that? Perhaps a macro?

Any suggestion will be appreciated. 

Regards,

LCC


Macro with the insertation of page number

$
0
0

I have set simple code which works without any error.

How to insert page numbers in the correct way and also close window 'Footer and Header' when it is done.

Sub ModifyContent1()
'
' ModifyContent1 Makro
'
'
    Selection.WholeStory
    Selection.Font.Name = "Calibri"
    Selection.Font.Size = 8
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    ActiveWindow.ActivePane.VerticalPercentScrolled = 0
End Sub

Please see an error when this is done.

Sub ModifyContent2()
'
' ModifyContent2 Makro
'
'
    Selection.WholeStory
    Selection.Font.Name = "Calibri"
    Selection.Font.Size = 8
    WordBasic.ViewFooterOnly
    ActiveDocument.AttachedTemplate.BuildingBlockEntries("Dve vrstici 2"). _
        Insert Where:=Selection.Range, RichText:=True
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

This will create an error:

    WordBasic.ViewFooterOnly
    ActiveDocument.AttachedTemplate.BuildingBlockEntries("Dve vrstici 2"). _
        Insert Where:=Selection.Range, RichText:=True



Select complete rows from a gridview using a checkbox and transfer to another webform

$
0
0

I need help to select information from a gridview not to delete, I´ve seen multiple ways to delete and I've tried to adapt it to my code but I'm having some issues with it, This is my gridview code

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"><Columns><asp:TemplateField><HeaderTemplate><asp:CheckBox ItemStyle-Width="150px" ID="cbSelect" runat="server" AutoPostBack="True" OnCheckedChanged="cbSelect_CheckedChanged" /></HeaderTemplate><ItemTemplate><asp:CheckBox ItemStyle-Width="150px" ID="cbSelected" runat="server" AutoPostBack="True" OnCheckedChanged="cbSelected_CheckedChanged" /></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Poliza"><ItemTemplate><asp:Label ID="Poliza" runat="server" Text='<%# Bind("POLIZA") %>'></asp:Label></ItemTemplate></asp:TemplateField><asp:BoundField ItemStyle-Width="150px" DataField="RAMO"
                HeaderText="Ramo" /><asp:BoundField ItemStyle-Width="150px" DataField="CERTIF"
                HeaderText="Certificado" /><asp:BoundField ItemStyle-Width="150px" DataField="NOMRMO"
                HeaderText="Ramo" /><asp:BoundField ItemStyle-Width="150px" DataField="CIA"
                HeaderText="N. Comp" /><asp:BoundField ItemStyle-Width="150px" DataField="NOMCIA"
                HeaderText="Compañia" /><asp:BoundField ItemStyle-Width="150px" DataField="RIF"
                HeaderText="Ident" /><asp:BoundField ItemStyle-Width="150px" DataField="CCT"
                HeaderText="Num" /></Columns></asp:GridView>

In my backend I have the code that fills the gridview which is working perfectly, also the code that evaluates if the checkbox has been checked.

Now, this is the code of my button that needs to pick the value of all the rows and transfer to another webform, normally I have done it with a "buttonfield" with "OnSelectedIndexChanged" but I can I do it with a checkbox?

protected void Button2_Click(object sender, EventArgs e)
 {
     List<string> test = new List<string>();

     foreach (GridViewRow gridViewRow in GridView2.Rows)
     {
         if (((CheckBox)gridViewRow.FindControl("cbSelected")).Checked)
         {
             string ejecutivoId = ((Label)gridViewRow.FindControl("Poliza")).Text;
             test.Add(ejecutivoId);
         }
     }
     if (test.Count > 0)
     {}



B2B

Mapping Visual Paradigm Diagrams in Word Document

$
0
0

Hello,

Is there any way by which i can somehow map or link the diagrams of visual paradigm in my word document?

So that in future any time when we change our diagram we don't need to update that diagrams manually in the word document.

Regards,

PKJ

Problem with recording macro in word Mac 2016

$
0
0

I am trying to set up a simple macro for something I do repetitively. I have lots of word documents for which I need to print just pages not to four all on one page.

I can print this successfully if I do it manually but when I record a macro it does not work and prints pages one to four on four pages

really frustrating.

This is the macro which was recorded 

Sub printpage()

'

' printpage Macro

'

'

    Application.PrintOut fileName:="", Range:=wdPrintRangeOfPages, Item:= _

        wdPrintDocumentContent, Copies:=1, Pages:="1-4", PageType:= _

        wdPrintAllPages, Collate:=True, Background:=False

End Sub

Sub Macro1()

'

' Macro1 Macro

'

'

End Sub

Any ideas how to rectify this by getting pages 1-4 printed on one page only.

Thank you

Lee

Adding Quick Parts Programmatically Using Word Office Model

$
0
0
I need to add Document ID Value quickpart to a very large number of existing documents and I would like to make a program to do so.  I'm afraid googling the issue has left me a little confused.  As far as I can tell, the rough form of the footer-insertion part of the solution (in C#) looks something like this:
    Word.Application iWord = new Word.Application();
            Word.Document iDoc = iWord.Documents.Open(savePath);
            foreach (Word.Section wordSection in iDoc.Sections)
            {
                Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                footerRange.DoSomething()
            }
            iDoc.Save();

But I can't seem to figure out the details of DoSomething().  

Please note that it must be the dynamic field, equivalent to Design->Quick Parts->Document Property->Document ID Value, not simply text.

Thanks!
Viewing all 4350 articles
Browse latest View live


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