Compile Error in Word
C# - Word Interop, Select Text That Has Just Been Pasted
Hi all,
This might be a really easy one for someone out there, but it is driving me round the bend !!!
I am using C# to populate a Word document by copying and pasting ranges.
If I paste a range using range.Paste(), is there an easy way to then select what I have just pasted? For example, I paste in a standard buffer and then want to replace items in the buffer I just pasted with something else.
I guess I am looking for some kind of 'handle' to the buffer I have just pasted, but it is eluding me at the moment.
Is this possible?
Many thanks in advance.
Scotty
problem repurposing EditUndo Word 2007
Hi,
I would like to repurposing the EditUndo command in Word but I noticed that the following routine will never be fired in Word 2007. (nor with CTRL-Z nor pushing the button)
Sub EditUndo()
MsgBox "Please, fire me!" End Sub
Notice that it will normally be fired in Word XP or Word 2010; and that the routine EditRedo is normally fired in all version of Word.
Sub EditRedo() MsgBox "Thanks for firing me!" End SubThanks for any help, Lauro
drop down list disappears
When I left click on a drop down option in any application with my mouse, the selections immediately disappear when I release the left mouse button.
Any suggestions?
“There was a problem sending the command to the program.”
Two environments:
2. New text Citrix upgrade Xenapp 6.5 on Windows 2008 R2 X64 servers
Windows 7 64bit
Office 2007 32bit
eDocs 5.3.1. patch 3
One user account – standard user test account. same rights on both environments
Issue only occurs on new citrix server 64 bit.
2. On a windows 7 64bit laptop the issue doesn’t occur.
The sys admins tell me it’s the same build.
Scenario:
1. Log onto citrix 64x
2. Word document on desktop
3. Word isn’t open.
4. Double click on word document to launch
The results:
Error message displays ‘There was a problem sending the command to the program.’
Click OK the document opens
Can work fine in Word
Same steps on the laptop 64bit
1. Log onto laptop 64x
2. Word document on desktop
3. Word isn’t open
4. Double click on word document to launch
The results:
Document opens successfully in Word – no error messages.
I’ve done a web search. people report this issue however on different applications and environments.
So far the recommendations aren’t applicable to me. These are the fixes I’ve applied so far without success.
- Re-register Words file extensions:
Close Word
Start > Run or press [WIN Key]+R
In the Run dialog type: winword.exe /r
Press OK
- Check settings for Run this program as administrator
In Start menu, select Word 2007, right mouse click, select Properties, select Compatibility un tick checkbox ‘Run this Program as an administrator.’
This wasn’t ticked in the first place
- Excel settings
Excel behaves correctly. I can replicate the same message if I change a setting in Excel Options, Advanced
Tick the checkbox ‘Ignore other applications that use Dynamic Data Exchange (DDE)’
However the same settings aren’t available in Word options. Which makes me think it’s a registry setting that needs updating for Word.
- Registry hack to turn off /dde
HKEY_CLASSES\ROOT\Applications\Winword.exe\Shell\Edit\Command
C:\Program Files\Microsoft Office\Office12\WINWORD.EXE" /n /dde
The result this works. Opens successfully no errors. However the document management system eDocs requires DDE to open files.
With the /dde switch removed it also launches multiple winword.exe sessions. Instead of the document being launched in the one winword.exe session.
Note: the laptop has the same registry value switches set and it works ie
C:\Program Files\Microsoft Office\Office12\WINWORD.EXE" /n /dde
- Run "Microsoft Office Diagnostics”
There must be a difference in the settings or configurations.
Any other suggestions I can implement.
dd
Word 2010 User Form - Repeating data
Hi:
I am a novice developer in Office. My focus at this time is Word 2010. I have developed a Word 2010 Template, placed text bookmarks, designed the "user input form" in VB and coded the fields I believe appropriately.
I am stumped on how to make the bookmarks in the Word template or the User Form Fields (content controls) in the Form repeat/populate information in other bookmarks that is initially put into one field of the screen presentation of the User Form. Example: "Supplier Name" field needs to populate three different places in the Word Template document. I have done some research as to REF fields but I am not sure if that is what I need to do or even how to do that if it is? When I experimented some of the bookmarks (with same name) in my template disappeared. I have found information regarding the design of filling in fields in the Template itself by Greg Maxey who also refers to articles by Suzanne Barhhill, but I can't seem to grasp how this might be applied to my needs? Any assitance would be greatly appreciated. The users want to have the graphical form presentation instead of a template document with the field controls in it for filling in.
Thanks
Maree Percival
Failed to create control. Licence information for this component was not found. Office 2013
I am trying to use Microsoft tabstrip control 6.0(SP6) in a VBA application. It works fine in Word 2013, but when I try to drop the object into another VBA container, I get the error: " Failed to create control. Licence information for this component was not found."
I never had this problem on machines with Office 2010 installed. Was there a change to the licence for 2013?
The PC is running Windows 7, 32 bit, and has Office 2013 home & buisness installed. The VBA container I am trying to drop the object into is Factory Talk View SE 6.1 (a Rockwell Automation product).
Run-time Error 5 "Invalid Procedure Call or Argument" when querying an Access table from Word
Hi everyone,
In Word 2013, I query an .accdb database with two extremely simple SQL strings:
Function GetDivisieID(Divisie As String) As String
Dim strSQL As String, varResult As Variant
strSQL = "SELECT Description, DivisionID FROM Divisions WHERE Description='" & Divisie & "'"
varResult = StartQuery(SQL:=strSQL, SortString:="", FunctionName:="GetDivisieID", Scheidingsteken:="")
GetDivisieID = LTrim(Str(varResult(0)))
End Function
Function GetTaalID(TaalAfk As String) As String
Dim strSQL As String, varResult As Variant
strSQL = "SELECT LanguageID, Description FROM Language WHERE Description='" & TaalAfk & "'"
' strSQL = "SELECT Language.LanguageID FROM Language"
varResult = StartQuery(SQL:=strSQL, SortString:="", FunctionName:="GetTaalID", Scheidingsteken:="")
GetTaalID = LTrim(Str(varResult(0)))
End Function
' StartQuery() merely exists to avoid duplicate lines of code
Private Function StartQuery(SQL As String, SortString As String, FunctionName As String, Scheidingsteken As String) As Variant
Dim conn As ADODB.Connection, strConn As String, rs As ADODB.Recordset
Dim lngN As Long, strResult() As String, strDB As String
Set StartQuery = Nothing
ReDim strResult(0)
strResult(0) = ""
strDB = modPaden.OWDatabase ' path to the database
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strDB & ";"
With conn
.Open (strConn)
.CursorLocation = adUseClient
End With
With rs
.Open SQL, conn ' <= the error occurs here
Set .ActiveConnection = Nothing
End With
If Not (rs.BOF And rs.EOF) Then
If SortString <> "" Then
rs.Sort = SortString
End If
rs.MoveLast
rs.MoveFirst
lngN = 0
While Not rs.EOF
Select Case FunctionName
Case "GetDivisieID"
strResult(lngN) = rs!DivisionID
Case "GetTaalID"
strResult(lngN) = rs!LanguageD
Case Else
End Select
rs.MoveNext
lngN = lngN + 1
ReDim Preserve strResult(lngN)
Wend
If Not (UBound(strResult) = 0 And strResult(0) = "") Then
ReDim Preserve strResult(UBound(strResult) - 1)
StartQuery = strResult()
End If
End If
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
End Function
My code calls GetDivisieID, which works fine, and immediately thereafter calls GetTaalID, which produces run-time error 5: "Invalid Procedure Call or Argument" when executingvarResult = StartQuery(.... When I use the even simpler strSQL = "SELECT Language.LanguageID FROM Language", commented out in the above code, the error occurs as well.
In Access, all three queries work. I have copied the contents of the SQL-view in Access in the Word VBA-editor in order to avoid typing mistakes.
Why does the error occur? How can I avoid it?
Thank you,
Cooz
Conditional formatting in content control and finding Picture Content control in a .docx
Hello,
I am almost near to complete my word document automation, but still facing 2 problems and I hope you can help me out of this:
1. Conditional Formatting: I wish to highlight text inside a content control according to their results which is either PASSED or FAILED (please see attachement).
object path = aActualResult; cControl.Range.InsertParagraphBefore(); //cOnctrol if Word.ContentControl type. Here I insert a new paragraph in content control object start = cControl.Range.Start; //Now I know where it starts Word.Range rb = SummaryDocument.Range(ref start, ref start); //Now I get the para range /** Here is do highlighting stuff **/ if (aStatus == "PASSED") rb.HighlightColorIndex = Word.WdColorIndex.wdBrightGreen; else rb.HighlightColorIndex = Word.WdColorIndex.wdRed; /**********************************/ /*****Here I add hyperlink *********/ object oTextToDisplay = System.IO.Path.GetFileName(aActualResult); rb.Hyperlinks.Add(rb, ref path, ref MISSING, ref MISSING, ref oTextToDisplay, ref MISSING); /**********************************/
Unfortunately, the above code does not work. Although I have highlighted the other content controls where the text is replaced instead of appended and it works without any problem and is simple.
2. Another problem is adding images in a picture content control box. Here is the piece of code I am using
cControl.Range.InlineShapes.AddPicture(aImagePath, ref MISSING, ref MISSING, ref MISSING); //cControl is Word.ContentControl object
The aove code adds another pic in the control without replacing the older one which I do not want.
If I iterate through the document to find Microsoft.Office.Tools.Word.PictureContentControl, I does not find the picture content control that I have inserted in template. If I am able to find it then it will be a lot easier because then I can simply replace pic by setting myPicControl.Image
foreach (Word.ContentControl cControl in SummaryDocument.ContentControls) { //do something } //Loop below does not return any of my pic control compnents foreach (Microsoft.Office.Tools.Word.PictureContentControl cControl in SummaryDocument.ContentControls) { //do something }
mso:StyleGalleryClassic
Hi,
Is it possible to change the size of the mso:StyleGalleryClassic control in Word2010 using customized ribbon xml?
We have customised styles with long names and the dropdown box is too small to display the full style names.
Is there an attribute I can specify in the xml file for the mso controls to change the size of the dropdown box?
<mso:control idQ="mso:StyleGalleryClassic" visible="true" />Thanks
ET
Accessing the new Insert control for tables in Word 2013
Setting styles order
Hi,
I've developed a Word 2010 template with a mix of user-defined and built-in styles. The styles are set to sort order "Recommended" and each style has the correct priority. The template also contain a form which allowes the user to enter pre-defined text. Everything works fine until the form is closed with unLoad, then the priority changes and the styles order gets messed up.
Is there any way to set priority with VBA, and also sort the styles with recommended order?
Regards,
Roger
Showing warning when MatchWildCard=True in France Locale in Microsoft word 2007
Word 2013: determine Lock Tracking status in VBA?
Word 2013 introduces the ability to keep Tracked Changes on unless a password is supplied:
Is there a way to determine whether this is set, or even to turn it on or off, in VBA?
I tried recording a macro to do it for investigation, but it only produced this:
ActiveDocument.Protect Password:="asdf", NoReset:=False, Type:= _ wdAllowOnlyRevisions, UseIRM:=False, EnforceStyleLock:=False
None of the .Protect parameters is relevant.
I need to be able to do this before I call a routine to accept all changes (which of course has run flawlessly until Word 2013). At present, that routine fails with Runtime Error 4605 (This command is not available) if Lock Tracking is on. I can of course use an On Error Goto, but it would be cleaner not to call the routine in the first place if I know Lock Tracking is on.
VBA Word 2007 close other window
hey there,
I'm a beginner in using VBA. Now I'm trying to make a program, but there is a problem, and I can't find a solution on Google.
If I open the document with the name 'Technische Handleiding Draaitafel_versie3', I want to close automatically the other Word windows with te names: 'Documentgenerator02' or 'Technische Handleiding Vlakke band_versie1'. Only one of the other screens can be open so it has to be a statement with 'else' in it.
I hope you can help me, and I hope my english is not too bad to understand because I'm Dutch.
Kind regards
Erik
How to insert a TOC info a Word doc via a macro
I want to write a macro to insert a TOC into a Word doc. The Word doc contains some text "INSERT TOC HERE". I want the macro to insert the TOC at that spot in the document (replacing the "INSERT TOC HERE" text). I'm using Office 2010.
I'm a newbie at VBA and can't figure out how to do this. Maybe some smart person on here can show me code that does it? Doesn't sound difficult, but Microsoft help is utterly useless.
Speed up mailmerge
Hi All
I’ve developed some VBA routines loading data from SQL Server and execute a mail merge. The template containing the VBA codes gets called from another executable (C++). That code has been written for a Word 2000 template. I’m migrating that code
to Word 2013 and have a major speed issue where I need your help.
For the Word 2000 solution I’ve already applied some VBA optimization code when I coded it years back:
«… Entry point VBA function …»
ActiveWindow.ActivePane.View.Type = wdNormalView
Application.ScreenUpdating = False
Options.Pagination = False
«... prepare mail merge …»
ActiveDocument.MailMerge.Execute True
«… rollback the ScreenUpdating, Pagination options …»
I even loaded the data into an RFT file on the local computer and used that document as a source for MailMerge, that was a big booster.
When I execute that code with Word 2000 it takes about 6 seconds to load 50 records into the RTF and have the MailMerge executed on that RTF as a datasource. Each document is one page long. I can use the same VBA code in Word 2013. If I execute the MailMerge
with the same 50 records it takes 72 seconds until the mail merge is done.
The big part of time used is during the command «ActiveDocument.MailMerge.Execute»: 65 seconds. The Word application is frozen with a black frame during that time so there is no GUI activity during the Mail Merge.
Does anybody have an idea on how to speed up the process and getting the values out of Word 2013 on what I’ve achieved with Word 2000?
Thanks for any help
Martin
VBS Image Replacement - Appearing as Gray Box with Filename
Hi :)
I'm hoping someone can assist me with an issue I'm having with MS Word and image replacements with VBS. The script itself works fine on one machine, yet copied to another machine with another installation of Office 2007 (same OS) it ends up having issues with replacing images.
The script looks like the below:
With oWordApp .Documents.Open("C:\Template.doc") .Documents(1).Activate() .ActiveWindow.ActivePane.View.SeekView = 9 .ActiveWindow.Selection.HeaderFooter.Shapes(2).LinkFormat.SourceFullName = "C:\test_logo.bmp" .ActiveWindow.Selection.HeaderFooter.Shapes(2).Select .ActiveWindow.Selection.Fields.Update .....
The script works fine on another system running the same version of Word 2007 (same OS). The script runs and completes, but the image for some reason doesn't seem to come through and looks like it's unsupported. On the other machine, where it works, the image comes out fine, but on this one installation it appears like this in the processed Word document:
<can't insert image>
Image shows a grey box with the label "test_logo.bmp" below it inside a Word Document opened inside Microsoft Office 2007.
The file is a BMP image file made in MS Paint so support shouldn't be a problem, and drag 'n' drop of the image works, as well as the 'Insert' method.
I don't believe the script is the issue since it works on another machine, and the image file and template are identical over the two machines. Is there some Word 2007 configuration that fixes this? Or is there some easy way to compare the Office Installations?
Writing to a table slows with time
Hello,
- I have been writing to a table that has 5 columns and all colums+rows contains text only (some formatting is done though)
- Each time I receive date from an external application. I create a new line in the table and simply write the data to it.
- I save the document after a page is written (approx 20 rows) in order to clean it regularly.
The issue is:
- The first row takes ca. 130 ms to write in the table.
- The time taken keeps on increasing with every row
- By the time I write 500th row, the time taken is ca. 900 ms.
I have tried it on 2 different computers. The behaviour is almost the same.
I have tried filling table using control components too, the result remains similar i.e. timings keep on increasing.
Is there any other way to make it reliable. Getting faster is one thing but it should be reliable at least with which I meant that the timings shall remain same or at least predictable.
The above behaviour is seen even when all the add-ins are deactivated and auto formatting, auto correction, spell-check etc is deactivated.
Thanks in advance!
Regards
Ricky
/****************************Edit Message***************/
I read reply to a similar problem from Cindy Meister. I really have no idea how ioen XML and word work together and what changed do I need to make in my code in order to integrate it, but it looks promising. Another question is, if I use Open XML, then can I show word document filling rows live Document.Visible = true; ??
/******************************************************/
Microsoft.Office.Interop.Word.RecentFile.Path throws COMException if recent file opened from Web
Hello.
I'm developing VSTO Add-In, and below is the code I'm using to delete entry from MRU list
string currentFullPath = Path.Combine(document.Path, document.Name); var recentItems = document.Application.RecentFiles.OfType<RecentFile>().ToList(); RecentFile recentItem = null; foreach (var item in recentItems) { string name = item.Name; string path = item.Path; // COMException here string fullPath = Path.Combine(path, name); if (currentFullPath == fullPath) item.Delete(); }
If the recent item was opened from any Web location via Internet Explorer, then I get COMException while trying to accessitem.Path
Stack trace and error message is below:
This is not a valid file name.
Try one or more of the following:
* Check the path to make sure it was typed correctly.
* Select a file from the list of files and folders.
System.Runtime.InteropServices.COMException
at Microsoft.Office.Interop.Word.RecentFile.get_Path() .....
I have implemented a workaround, but it's a bug in API, that would be better to fix.
Thank you in advance.