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

Insert an empty Signature into Word document

$
0
0

Hello everyone,

I would like to sign my MSWord documents using .Net Office-interop. 

I do know that one can insert an signature field using the following lines.

                    object sigID = "{00000000-0000-0000-0000-000000000000}";
                    SignatureSet signatureSet = oWordDoc.Signatures;
                    Signature objSignature = signatureSet.AddSignatureLine(sigID);

I also know that one can insert an invisible signature that does not modify document's layout using the following command.

Signature objSignature = signatureSet.AddNonVisibleSignature();

However this line requires to sign the document immediately and this is now exactly what I want.

Here is what I want, I want to insert an invisible  signature field and sign it later with an API. If I insert a signature line it defies the requirement; Document layout should be intact. Does anyone know how to insert an invisible signature line or a nonvisible signature without signature.

Thanks everyone


Reviewing Pane getting corrupted in Word 2013

$
0
0

Hi,

I am having some stability issues in my Word Addin with Reviewing Pane open in Word 2013.

I have reproduced the corruption issue in word document without my addin as well. Steps to reproduce are:

i. Create a new word document and insert two paras say "One" & "Two"
ii. Now Turn ON track changes and insert another para with text "Three"
iii. Now click Reviewing pane, to open it. "Three" is visible there. 
iv. In Reviewing Pane, place your cursor on Three (dont select, just place), run this macro:

selection.text = demo

This corrupts the reviewing pane i.e entire main document content comes in reviewing pane. Sometimes it doesn't happen right away, but if user repeated clicks between Reviewing pane and Main Document, the corruption is visible.

Sometimes even tracked text also goes away.

Pls rerun the steps a couple of times if it's not reproducible in first shot (as the behaviour is somewhat weird).

Regards,
Rahul


AppCrash error wwlib.dll in Microsoft Word 2010

$
0
0
Hi,

My name is Gururajan.

I am getting an AppCrash error while running the VBA script that removes double space in the footnotes/endnotes section in Microsoft Word 2010. Below is the error details. 



Problem Event Name: AppCRASH

Application Name: WINWORD.EXE

Application Version: 14.0.7015.1000

Application Timestamp: 51cca7cc

Fault Module Name:wwlib.dll

Fault Module Version: 14.0.7015.1000

Fault Module Timestamp: 51cca86e

Exception Code:c0000005

Exception Offset:00ad65f3

OS Version:6.1.7601.2.1.0.256.48

Locale ID:1033

LCID:1033

Skulcid:1033



Please suggest how to rectify this problem.



Regards,

Gururajan












Suggestions for improvements

$
0
0

I don't know if this is the right forum for this but I use Microsoft Word, Excel, and Powerpoint often and there are some things I wish I could do in these programs.

 

For one, I wish Microsoft Word would allow me to put a placesetter on the spot where I have to break off when reading or editing a document while I move to read another document. It is always hard to find the same spot when I return. I need a one-click easy to place, easy to find, and easy to get rid off marker.

 

I have other ideas too, but first I wanted to see if this was the right forum.

Regression bug in Word 2013 concerning Document.ContentControlOnExit

$
0
0

Hi,

If you create a Content Control inside of a TextBox and then click somewhere outside both the Content Control and the TextBox the ContentControlOnExit event will not be fired.

Clicking inside of the TextBox (but outside of the Content Control) as well as using the arrow keys to navigate outside of the Content Control fires the event correctly.

This behaviour is not observable in Word 2010.

Best regards,

Repeating Section Content Control "Placeholder text"

$
0
0

There does not appear to be any way to set the placeholder text on a repeating section content control. In fact it appears that what looks like placeholder text in a repeating section content control is something entirely different.

I open a new document in Word 2013 and type "Test" then hit enter.  Next I run this code:

Sub Test()
Dim oCC As ContentControl
Dim oPHT As Object
  'Add a new repeating section CC.
  Set oCC = Selection.Range.ContentControls.Add(wdContentControlRepeatingSection, Selection.Range)
  'It looks like it is showing placeholder text, but apparently not.
  If oCC.ShowingPlaceholderText Then
    Debug.Print oCC.PlaceholderText
  End If
  'Attempt to set placeholder text to a range.
  oCC.SetPlaceHolderText , ActiveDocument.Words(1)
  Set oPHT = oCC.PlaceholderText
  Debug.Print oPHT.Value
  'It set, but the CC looks the same "Enter any ..."
  'Attempt to set placeholder text to a string.
  oCC.SetPlaceHolderText Text:="Test"
  Set oPHT = oCC.PlaceholderText
  Debug.Print oPHT.Value
  'Again it set, but the CC looks the same "Enter any ..." :-(
  If oCC.ShowingPlaceholderText Then
    Debug.Print oCC.PlaceholderText
  End If
End Sub

Does anyone know what the default  "Enter any content that you want to repeat ..." really is and if there is a programmatic way to alter/define it?

Thank!


Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

Ribbon Customisation - how do I change/remove the 'Tell me more' link to Word Help?

$
0
0

I have added a custom tab, group, buttons etc onto my word ribbon using xml and linked them back to vba macros. All of that works.

But when I move the cursor over any of my buttons, I can see:
Screentip text that I entered in xml
Name of the template where the xml/vba resides
Tell me more - a clickable link that opens the main Word help file

The main word help file isn't relevant to my custom button. So I'd like to either remove that link or change it so it opens my own .chm help file. Is there an attribute that I can add that does that?

Microsoft.Office.Interop.Word.dll is Access Denied

$
0
0

We wish to use Microsoft.Office.Interop.Word.dll from C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14 on server machine. But, the web application gives 'access denied' error when run on the client machine.

May we know how can we solve this issue?

Looking forward to your response.


Thanks,

Ram


Cannot seek primary header view through VBA

$
0
0
The call ThisDocument.ActiveWindow.View.SeekView = wdSeekPrimaryHeader failing for some documents producing run time exception 5895: Requested view is not available. The call should not fail. Could it be something specific to the document structure?

Parul Gupta

Performance issues with application level add-in in word 2013

$
0
0

Hi,

I’m working on an application level addin(with ribbon controls) for word 2013 and we have some performance issues.

The performance issue is when we create a new document or open an existing document.

Our addin is designed to have its own tab with a bunch of controls that does different things to the active document.

There are a couple of things that needs to run during initialization of our addin in order to populate some of the

controls. We are in fact making 3 calls to a rest service during startup among a couple of other small things.

If i take theses 3 calls out i can see a performance increase but it still takes a lot of time before word shows the document

to the user.

If a make a comparison:

  1. Open up a document without the addin from the user desktop takes about 1-2 seconds
  2. Open up a document with the addin takes about 5-6 seconds.
  3. Open up a document with the addin(taken the 3 calls to the service out) takes 4-5 seconds.
  4. According to the following article http://msdn.microsoft.com/en-us/library/bb386106.aspx we can
    adjust the LoadBehaviour. I have set its value to 16. Opens up the document the first time(5-6 seconds).
    The second time I open up the document it takes about 2-3 seconds. 2-3 seconds is acceptable performance.

    However, since the addin is now loaded on demand a couple of things that are supposed to run during
    initialization runs only when the user interacts with any user control within our addin. Are there perhaps
    some other event that I can listen to in order to initialize the ribbon controls and processing of the open document?

I realize this is not much to go on but are there any other performance optimizations that can be done?

Br,

/Peter


Peter

C++ IDispatch, Create Table within Microsoft Word

$
0
0

Hello All,

I am having trouble creating a table within Microsoft Word using the IDispatch. I have successfully created a new document, added an image and some text and created an IDispatch for Tables (pWordTables).

Now I am attempting to add a new table but I cannot figure out how to accomplish this. Can anyone assist?

Below is my code.

                                        

void CpwSCDOT_SolicitationsDialog::OnWordTest()
{
  CoInitialize(NULL);  CLSID clsid;
  HRESULT hr = CLSIDFromProgID(L"Word.Application", &clsid);
  if(FAILED(hr)) 
     return;

  IDispatch *pWordApp;  hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **) &pWordApp );
  if(FAILED(hr)) 
     return;

   CWordAutowrap wd;

   {
      VARIANT param;
      param.vt = VT_I4;
      param.lVal = 1;

      hr = wd.AutoWrap(DISPATCH_PROPERTYPUT, NULL, pWordApp, L"Visible", 1, param);
      if(FAILED(hr)) 
      {
         VariantClear(&param);
         pWordApp->Release();
         return;
      }
      VariantClear(&param);
   }

   IDispatch *pWordDocuments;
   {
      VARIANT result;
      VariantInit(&result);

      hr = wd.AutoWrap(DISPATCH_PROPERTYGET, &result, pWordApp, L"Documents", 0);
      if(FAILED(hr))
      {
         pWordApp->Release();
         return;
      }
      pWordDocuments = result.pdispVal;
   }

   IDispatch *pWordDoc;
   {
      VARIANT result;
      VariantInit(&result);

      hr = wd.AutoWrap(DISPATCH_METHOD, &result, pWordDocuments, L"Add", 0);
      if(FAILED(hr))
      {
         pWordDocuments->Release(); 
         pWordApp->Release();
         return;
      }
      pWordDoc = result.pdispVal;
   }

{
VARIANT result;
VariantInit(&result);

wd.AutoWrap(DISPATCH_METHOD, &result, pWordDoc, L"Activate", 0);
}

CString sFullname = _T("");
{
VARIANT result;
VariantInit(&result);

wd.AutoWrap(DISPATCH_PROPERTYGET, &result, pWordDoc, L"FULLNAME", 0);
sFullname = result.bstrVal;
}

IDispatch *pSelection;
    {
        VARIANT result;
        VariantInit(&result);
hr = wd.AutoWrap(DISPATCH_PROPERTYGET, &result, pWordApp, L"Selection", 0);
if(FAILED(hr))
{
pWordDoc->Release();
pWordDocuments->Release();
pWordApp->Release();
return;
}
        pSelection=result.pdispVal;
    }

IDispatch *pFont;
    {
        VARIANT result;
        VariantInit(&result);
hr = wd.AutoWrap(DISPATCH_PROPERTYGET, &result, pSelection, L"Font", 0);
if(FAILED(hr))
{
pWordDoc->Release();
pWordDocuments->Release();
pWordApp->Release();
return;
}       
pFont=result.pdispVal;
    }

{
VARIANT param;
param.vt = VT_BOOL;
param.boolVal = TRUE;

wd.AutoWrap(DISPATCH_PROPERTYPUT, NULL, pFont, L"Bold", 1, param);
VariantClear(&param);
}

IDispatch *pInlineShapes;
{
VARIANT result;
VariantInit(&result);
hr = wd.AutoWrap(DISPATCH_PROPERTYGET, &result, pSelection, L"InlineShapes", 0);
if(FAILED(hr))
{
pSelection->Release();
pFont->Release();
pWordDoc->Release();
pWordDocuments->Release();
pWordApp->Release();
CoUninitialize();
return;
}
pInlineShapes=result.pdispVal;
}

{
VARIANT param;
param.vt = VT_BSTR;
param.bstrVal = SysAllocString(L"C:\\Images\\evaluator1.png");

wd.AutoWrap(DISPATCH_METHOD, NULL, pInlineShapes, L"AddPicture", 1, param);
}

{
VARIANT param;
param.vt = VT_BSTR;
CString sValue = _T("");
sValue.Format(L"\nPROJECT: %s\n", m_ProjectName);
param.bstrVal = ::SysAllocString(sValue);

wd.AutoWrap(DISPATCH_METHOD, NULL, pSelection, L"TypeText", 1, param);
VariantClear(&param);
}

{
VARIANT param;
param.vt = VT_BSTR;
CString sValue = _T("");
sValue.Format(L"CRITERIA LIST:\n");
param.bstrVal = ::SysAllocString(sValue);

wd.AutoWrap(DISPATCH_METHOD, NULL, pSelection, L"TypeText", 1, param);
VariantClear(&param);
}

{
VARIANT param;
param.vt = VT_BSTR;
CString sValue = _T("");
sValue.Format(L"\tCRITERIA #\tQUESTIONS\t\t\t\t\t\t\tWEIGHTS\n");
param.bstrVal = ::SysAllocString(sValue);

wd.AutoWrap(DISPATCH_METHOD, NULL, pSelection, L"TypeText", 1, param);
VariantClear(&param);
}

{
VARIANT param;
param.vt = VT_BOOL;
param.boolVal = FALSE;

wd.AutoWrap(DISPATCH_PROPERTYPUT, NULL, pFont, L"Bold", 1, param);
VariantClear(&param);
}

CString sTemp = _T("");
CString sCriteriaNumber = _T("");
CString sCriteriaWeight = _T("");
CString sCriteriaQuestion = _T("");
int iIndex = 0;

int iCount = m_ArrayCriteria.GetCount();

for(iIndex = 0; iIndex < iCount; iIndex++) 
{
sTemp = m_ArrayCriteria.GetAt(iIndex);

int i1 = sTemp.Find(L":");
sCriteriaNumber = sTemp.Mid(0, i1);
int iTemp = sTemp.GetLength() - (i1 + 1);
CString sTemp2 = sTemp.Right(iTemp);
int i2 = sTemp2.Find(L":");
sCriteriaWeight = sTemp2.Mid(0, i2);
sCriteriaQuestion = sTemp2.Mid(i2 + 1);

{
VARIANT param;
param.vt = VT_BSTR;
CString sValue = _T("");
sValue.Format(L"\t\t%s\t%s\t\t\t\t\t\t%s\n", sCriteriaNumber, sCriteriaQuestion,sCriteriaWeight);
param.bstrVal = ::SysAllocString(sValue);

wd.AutoWrap(DISPATCH_METHOD, NULL, pSelection, L"TypeText", 1, param);
}
}

{
VARIANT param;
param.vt = VT_BOOL;
param.boolVal = TRUE;

wd.AutoWrap(DISPATCH_PROPERTYPUT, NULL, pFont, L"Bold", 1, param);
VariantClear(&param);
}
{
VARIANT param;
param.vt = VT_BSTR;
CString sValue = _T("");
sValue.Format(L"SCORES LIST:\n");
param.bstrVal = ::SysAllocString(sValue);

wd.AutoWrap(DISPATCH_METHOD, NULL, pSelection, L"TypeText", 1, param);
}

{
VARIANT param;
param.vt = VT_BSTR;
CString sValue = _T("");
      sValue.Format(L"\tFIRM NAME\tCRITERIA #\tCOMMENTS\t\t\t\t\tSCORES\n");
      param.bstrVal = ::SysAllocString(sValue);

      wd.AutoWrap(DISPATCH_METHOD, NULL, pSelection, L"TypeText", 1, param);
   }

   IDispatch *pWordTables;
   { 
      VARIANT param;
      param.vt = VT_BOOL;
      param.boolVal = false;

      hr = wd.AutoWrap(DISPATCH_PROPERTYGET, NULL, pWordDoc, L"Tables", 0); 
      if(FAILED(hr)) 
         TRACE(L"Failed to create tables dispatcher.");

      VariantClear(&param);
   }

   IDispatch *pWordTable;
   { 
     VARIANT param1, param2, param3;
      param1.vt = VT_I4;// Rows
      param1.lVal = 9;
      param2.vt = VT_I4;// Columns
      param2.lVal = 2;

/**********  I THINK THIS IS WHERE THE ISSUE IS ***************/
      param3.vt = VT_BSTR; // Range
      param3.bstrVal = ::SysAllocString(L"Selection");

/**********  I THINK THIS IS WHERE THE ISSUE IS ***************/

      hr = wd.AutoWrap(DISPATCH_METHOD, NULL, pWordTables, L"Add", 3, param3, param2,        param1); 
      if(FAILED(hr)) 
         TRACE(L"Failed to create tables dispatcher.");

      VariantClear(&param1);
      VariantClear(&param2);
      VariantClear(&param3);
   }

   { 
      VARIANT param;
      param.vt = VT_BOOL;
      param.boolVal = false;

      hr = wd.AutoWrap(DISPATCH_METHOD, NULL, pWordDoc, L"Close", 1, param); 
      if(FAILED(hr)) 
         TRACE(L"Failed to close Word document.");

      VariantClear(&param);
   }

  {
   wd.AutoWrap(DISPATCH_METHOD, NULL, pWordApp, L"Quit", 0);
   if(FAILED(hr)) 
     {
         TRACE(L"Failed to Quit Word application.");
         return;
      }
   }
   pWordDoc->Release();
   pWordDocuments->Release();
   pWordApp->Release();
   CoUninitialize();
}





How to "decorate" words or ranges in Word?

$
0
0

I am building a Word Add-in which scans the document for misplaced words. It works like a spell checker by using a dictionary. The spell checker in Word places a curly red line beneath the word and I want to decorate my misplaced words in the same way or by a customized symbol placed on the actual word in the document window.

How can I do that? Where to find documentation on the issue?

It is very important that this decoration don't change the actual document, so "underline", "highlight","Bold" or "italics" is not an option.

Thanks Anders FJ

Problem with repeating section content control in word 2013

$
0
0

Hi,

I’m trying to merge two documents with information from an underlying service.

The first document which is an active document(opened in word and visible to the user) is to be merged

with a second document coming from an underlying service.

I’m using components like OPCHelper to flaten out the document to an xml which I can insert into the

First open document. That being said, now to the problem.

The problem that I have is with the “repeating section content control” in word 2013. The content control

does not seem to update and show new records from the underlying CustomXml. I have checked that the first

document does indeed have all the records stored within its CustomXml. It’s the “repeating section content control”

that simply does not show them. However, here is the funny part, if I run the routine again(which updates the first document

with info from the second document) the “repeating section content control” SHOWS the records correctly.

I think this is a small thing to fix but I have tried many different things and searched for answers to this problem. Since

Word 2013 and “repeating section content control” is quite new I guess not many solutions are out there.

So, here is the routine that is updating/merging the two documents. UpdateDocument coordinates the merging process

Where the first parameter is the active document and the second parameter is the same document updated with more

records that should be displayed by the “repeating section content control”.

 

       publicstaticvoid UpdateDocument(this Word.Document doc, byte[] input,string pNamespace)

       {

           doc.Application.ScreenUpdating=false;

           if (input!=null)

           {

               using (MemoryStream ms =newMemoryStream())

               {

                   ms.Write(input,0, input.Length);

                   using (WordprocessingDocument wordDocument =WordprocessingDocument.Open(ms,true))

                   {

                       //wordDocument.MainDocumentPart.Document.Save();

                       //wordDocument.Package.Flush();

                       XDocument xDoc= OpcToFlatOpc(wordDocument.Package);

                       string openxml= xDoc.ToString();

                       doc.Range().InsertXML(openxml);

                       // Add CustomXmlPart

                       CustomXmlPartCore customXmlPartCore=newCustomXmlPartCore(pNamespace);

                       CustomXmlPart customPart= customXmlPartCore.GetCustomXmlPart(wordDocument.MainDocumentPart);

                       if (customPart!=null)

                       {

                           XDocument customPartDoc=null;

                           using (XmlReader reader =XmlReader.Create(customPart.GetStream(FileMode.Open,FileAccess.Read)))

                           {

                               customPartDoc =XDocument.Load(reader);

                           }

                           doc.StoreCustomXmlPart(customPartDoc, pNamespace);

                       }

                   }

               }

           }

           

           doc.Application.ScreenUpdating=true;

       }

       /// <summary>

       /// Stores the custom XML part.

       /// </summary>

       /// <param name="document">The document.</param>

       /// <param name="customXmlPartDocument">The custom XML part document.</param>

       /// <returns></returns>

       publicstaticCustomXMLPart StoreCustomXmlPart(this Word._Document document, XDocument customXmlPartDocument,string pNamespace)

       {

           CustomXMLPart part=null;

           if (document!=null&& customXmlPartDocument!=null)

           {

               CustomXMLParts parts= document.CustomXMLParts.SelectByNamespace(pNamespace);

               

               if (parts.Count>0)

               {

                   //Debug.Assert(parts.Count == 1);

                   parts[1].Delete();

               }

               part = document.CustomXMLParts.Add(customXmlPartDocument.ToString(),Type.Missing);

           }

           return part;

       }

Some resources that I have used are:

http://msdn.microsoft.com/en-us/library/ff191178.aspx

http://worddocgenerator.codeplex.com/documentation

(SampleRefreshableDocumentGenerator)

Any help would be much appreciated.

Br,

/Peter Johansson


Peter

Fresh install of Office 2013 - Excel Window shows during interop even though it was activated with wdOLEVerbHide

$
0
0

I have the strangest issues with Office 2013.  Here's the setup.

1.  Clean install of Windows 7 SP1
2.  Install Office 2013, the only version of Office on this machine.
3.  Run Word.exe and Excel.exe to let it do its initialization thing
4.  Run our Interop code, which operates on a Word doc (2003) with embedded Excel charts.  When the code runs, I see Excel windows opening up and going away as it operates on the charts.

The strange thing is, after a few times doing this, the Excel windows stop showing up.  Almost always.  We had one machine that the Excel windows didn't stop showing up.  On this machine, I was able to get the Windows to not show up by running both the Word and Excel executables with the /regserver switch.

For each of the graphs being operated on, we are activating the object with the "wdOLEVerbHide" parameter:

m_Document.InlineShapes.Item(i).OLEFormat.DoVerb(Word.WdOLEVerb.wdOLEVerbHide)

We tried running Word.exe and Excel.exe with the /regserver switch before our first run of our interop code and the Excel windows still showed up.  

This is not acceptable for our product, and this does not happen for any of the previous versions of Office, just 2013.  Anyone have any idea why it is not honoring the "Hide" flag, and why sometimes it corrects itself?  

Thanks,
Terry

CommandBar popup behaviour in Word2013

$
0
0

Crossposted at http://www.vbaexpress.com/forum/showthread.php?47029-Word-2013-Spelling-Context-Menu-AutoCorrect-command (something very similar)

I've been noticing a few posts in other forums regarding MS decision to remove the AutoCorrect feature from the right click spelling context menu.  Personally I don't think I've ever noticed it, but was interested in seeing if it could be put back.

I've noticed in the past when MS removes a useful or (useless feature) from the UI, the underlying tool is still available so I thought I could just customize the spelling context right click menu by adding the CommandBarPopup ID 30066 back to the spelling command bar.  I was able to do that with no problem, but oddly the built-in popup does not behave like the built-in popup in other Word versions.  It is there, but it has no content.  It doesn't duplicate the list of suggested corrections list at the top of the spelling menu and it doesn't contain the built-in AutoCorrect options command buton.  It is just an empy popup :-(

Not to be discouraged, I pressed on and I've managed cobble together a process that will replicate the process in earlier versons of Word, but at a cost in overhead that will likely make it useless.  The only thing I could think to do was to manually add the list of suggested spellings in the AutoCorrect popup and manually add the AutoCorrect options button. I then created a macro to replicate (as best I could) Word's native process for creating autocorrect entries from the popup.  The nasty part is that the spelling command bar has to be reset and recreated with each selection change.  That is the cost in overhead that makes the whole thing questionable.  You can download a template containing the code: http://gregmaxey.mvps.org/word_tip_pages/customize_shortcut_menu.html

I realize it is a lot of code, but if anyone looks at it and can see something I've done that prevents the built-in AutoCorrect popup from working like it seems it should then this might but a useful tool.  Thanks.

Standard code:

Option Explicit
Public p_ThisApp As clsThisApp
Sub AutoExec()
  InitiateAppClass
End Sub
Sub AutoOpen()
  InitiateAppClass
End Sub
'Call this pocedure to initialize the clase

Public Sub InitiateAppClass()
  Set p_ThisApp = Nothing
  Set p_ThisApp = New clsThisApp
lbl_Exit:
  Exit Sub
End Sub

Sub BuildControls()
Dim oPopUp As CommandBarPopup
Dim oCtr As CommandBarControl
Dim oBtn As CommandBarButton
Dim lngIndex As Long
Dim lngMarker As Long
  
  CustomizationContext = ThisDocument.AttachedTemplate
  'Prevent double customization
  Set oPopUp = CommandBars.FindControl(Tag:="BuiltInAC")
  If Not oPopUp Is Nothing Then GoTo lbl_Exit
  On Error GoTo lbl_Exit
  'Determine where the "Ignore All" control is located. This tells us how many suggested spellings are in the context menu.
  lngMarker = CommandBars("Spelling").Controls("&Ignore All").Index
  'Add the built-in AutoCorrect popup
  Set oPopUp = CommandBars("Spelling").Controls.Add(msoControlPopup, 30096, , CommandBars("Spelling").Controls("&Hyperlink...").Index, 1)
  With oPopUp
   .Tag = "BuiltInAC"
   .BeginGroup = True
  End With
  'I would have thought that the built-in popup would include the suggested spelling and the AutoCorrect options dialo, but it doesn't.
  'Yuck.  This means that they will have to be fudged and added\removed with each selection change :-(
  For lngIndex = 1 To lngMarker - 1
    Set oBtn = oPopUp.Controls.Add(msoControlButton, CommandBars("Spelling").Controls(lngIndex).ID)
    With oBtn
      .Caption = CommandBars("Spelling").Controls(lngIndex).Caption
      .Style = msoButtonCaption
      .Tag = CommandBars("Spelling").Controls(lngIndex).Caption
      .OnAction = "CreateAutoCorrect"
    End With
  Next lngIndex
  'Add the built-in AutoCorrect Options dialog
  Set oBtn = oPopUp.Controls.Add(msoControlButton, 793)
  ThisDocument.Saved = True
lbl_Exit:
  Set oPopUp = Nothing
  Set oBtn = Nothing
  Exit Sub
End Sub

Sub RemoveContentMenuItem()
  CustomizationContext = ThisDocument.AttachedTemplate
  CommandBars("Spelling").Reset
  ThisDocument.Saved = True
lbl_Exit:
  Exit Sub
End Sub

Sub CreateAutoCorrect(Optional strWord As String)
Dim cmdBCtl As CommandBarControl
Dim oRng As Word.Range
Dim arrChars() As String
Dim lngLen As Long, lngIndex As Long
Dim strAppend As String
  Set cmdBCtl = Application.CommandBars.ActionControl
  Set oRng = Selection.Words(1)
  lngLen = Len(oRng)
  If lngLen <> Len(Trim(oRng)) Then
    ReDim arrChars(lngLen - Len(Trim(oRng)) - 1)
    For lngIndex = 0 To UBound(arrChars)
      arrChars(lngIndex) = Mid(oRng, Len(Trim(oRng)) + lngIndex + 1, 1)
    Next
  End If
  Application.AutoCorrect.Entries.Add Name:=Trim(oRng), Value:=cmdBCtl.Tag
  For lngIndex = 0 To UBound(arrChars)
    strAppend = strAppend & arrChars(lngIndex)
  Next lngIndex
  Selection.Words(1) = cmdBCtl.Tag & strAppend
  RemoveContentMenuItem
lbl_Exit:
  Exit Sub
End Sub

Class

Option Explicit
Private WithEvents m_oThisApp As Application

Private Sub Class_Initialize()
  Set m_oThisApp = Word.Application
  cls_Initialize_Reset
lbl_Exit:
  Exit Sub
End Sub

Private Sub m_oThisApp_DocumentOpen(ByVal doc As Document)
  cls_Initialize_Reset
lblbl_Exit:
  Exit Sub
End Sub

Private Sub m_oThisApp_DocumentChange()
  cls_Initialize_Reset
lbl_Exit:
  Exit Sub
End Sub

Private Sub m_oThisApp_WindowSelectionChange(ByVal Sel As Selection)
  cls_Initialize_Reset
lbl_Exit:
  Exit Sub
End Sub

Private Sub cls_Initialize_Reset()
Dim lngCur As Long
  On Error GoTo lbl_Exit
  lngCur = System.Cursor
  System.Cursor = wdCursorNormal
  Module1.RemoveContentMenuItem
  Module1.BuildControls
  On Error GoTo 0
  System.Cursor = lngCur
lbl_Exit:
  Exit Sub
End Sub







Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm


PDF converstion in Word 2013:Execute problem

$
0
0

Hi,

I have written some code which performs a PDF conversion using word 2013 using activex controls. The program is installed on a terminal server which is then accessed by terminals. One of the admin users can run the code fine and is very happy however when we change to a different user we get:

"error ocurred accessing component property/method: EXECUTE, This method or property is not available because the command is not available for reading. Error code 0x80020009 [program] (5890)

We have tried adding the person to be an admin, no joy. We have gone into word and checked the trust centre and this matches the admins setup. I don't think it's the code as it works for one person but not another. We've checked folder security. Can anyone offer any assistance as it would be greatly appreciated.

thanks

Steve

Trouble restricting editing of footer

$
0
0

I'm writing a small C# program to fix up our templates.  I don't want the user to be able to edit the footer of a document, so I tried the following:

foreach (Word.Section wordSection in currentDoc.Sections)
            {
                    footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                    Word.ContentControl cc = currentDoc.ContentControls.Add(Word.WdContentControlType.wdContentControlGroup, footerRange);
                    cc.LockContentControl = true;
                    cc.LockContents = true;
                }

but receive the error " This method or property is not available because a document window is not active." on the .Add() line.  Am I misunderstanding something here?  Is there a better way to restrict editing of only the footer?



Tab setting

$
0
0

I need a macro to highlight wherever the Tab position set greater than 1 inch in tables in the the word document (all the tabs are in Inches).

The Macro should be able to highlight all the different alignment of the tabs (left or right or decimal etc.....in the document.

The Line of the text marked with the tabs can be highlighted or font color can be changed to red to indicate that the line has some tab which is greater than 1 inch.

And also I need other macro which can highlight if a hanging indent goes less than 0 inches.

This all regards to find the text hidden manually within tables

Could anyone help on this?

John

How to covert word tables to clean HTML format using C#

$
0
0

Hi all

I have a word file with few tables in it, when I convert word to filtered HTML using C#, word add extra tags in it for tables, How do I remove them ?

I just want text-align, bold, italic, underline, cell width, cell border tags in html

How can I remove unnecessary tags   ?

Thanks in advance for help

Using REGEX with Find and Replace in Word

$
0
0

Is it possible to replace things with REGEX.

For example, I am going through a word document right now looking for all 3 letter words using <???> I would like to add two zeros at the end of these words.

What would I put in the the "replace with:" field to add two zeros to each word?

Viewing all 4350 articles
Browse latest View live


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