We are currently embarking on developing a custom EncryptionProvider for Office decryption.
Does anyone know where there is sample code (c#, or c++) to help us get started?
We are currently embarking on developing a custom EncryptionProvider for Office decryption.
Does anyone know where there is sample code (c#, or c++) to help us get started?
How do I get the Ask prompt \o switch to work correctly when executing mail merge from a macro? I'm running mail merge from word. The mail merge document has an Ask prompt with the \o switch telling it to ask only once. When running the mail merge directly from Word, the prompt appears only once. When executing the mail merge within a macro, the prompt appears for every record. The user will run the mail merge from either Word or use the macro, depending on the scenario.
Thanks for your assistance.
Hi, I want to create a report using word document.
I just want to make my table row lower like the image below(the second table).Here's my code so far
public static void createWord () { int row = 1; Microsoft.Office.Interop.Word.ApplicationClass app = new ApplicationClass(); app.Visible = true; object start = 0; object end = 0; object Null = System.Reflection.Missing.Value; object autofit = WdAutoFitBehavior.wdAutoFitFixed; Document doc = new DocumentClass(); doc = app.Documents.Add(ref Null, ref Null, ref Null, ref Null); //header____________________________________________________________________________________________________________________________ Microsoft.Office.Interop.Word.Paragraph header = doc.Paragraphs.Add(ref Null); header.Range.Text = "This is a header\nand this is sub header"; //header____________________________________________________________________________________________________________________________ Connection.open(); OleDbCommand selectstudent = new OleDbCommand("select * from bookstable where booksid=@a", Connection.connection); selectstudent.Parameters.AddWithValue("@a", L.StudInfo.studentid); OleDbDataReader readstudent = selectstudent.ExecuteReader(); OleDbCommand count = new OleDbCommand("select count(*) from bookstable where booksid=@a",Connection.connection); count.Parameters.AddWithValue("@a", L.StudInfo.studentid); //table____________________________________________________________________________________________________________________________ Microsoft.Office.Interop.Word.Table borrower = doc.Tables.Add(doc.Range(ref start, ref end), Convert.ToInt32(count.ExecuteScalar()), 5, ref Null, ref autofit); borrower.Range.Font.Name = "segoe ui light"; borrower.Range.Font.Size = 8; borrower.Range.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle; borrower.Borders.Enable = 1; borrower.AutoFitBehavior(WdAutoFitBehavior.wdAutoFitContent); borrower.AutoFitBehavior(WdAutoFitBehavior.wdAutoFitFixed); borrower.AllowAutoFit = true; while(readstudent.Read()) { string remarks = ""; borrower.Rows[row].Cells[1].Range.Text = readstudent.GetStringOrNull("btitle"); borrower.Rows[row].Cells[2].Range.Text = readstudent.GetStringOrNull("bauthor"); borrower.Rows[row].Cells[3].Range.Text = readstudent.GetStringOrNull("bcode"); borrower.Rows[row].Cells[4].Range.Text = readstudent.GetStringOrNull("bdateborrowed") + "\n" + readstudent.GetStringOrNull("btimeborrowed"); string ids = readstudent.GetStringOrNull("bookremarksid"); OleDbCommand selectremarks = new OleDbCommand("select * from remarkstable where remarksid = @a", Connection.connection); selectremarks.Parameters.AddWithValue("@a", ids); OleDbDataReader readreamarks = selectremarks.ExecuteReader(); while(readreamarks.Read()) { remarks += readreamarks.GetStringOrNull("count") + "-" + readreamarks.GetStringOrNull("datereturned") + "-" + readreamarks.GetStringOrNull("timereturned") + "-" + readreamarks.GetStringOrNull("remarks")+"\n"; } borrower.Rows[row].Cells[5].Range.Text = remarks; borrower.Rows[row].Height = 1; row++; } Connection.close(); }
Hi,
I just want to check if the header of a word document has focus or not (Any part of the header). If the header has the focus then it should display a message. An independent VBA function that can be called anywhere.
Focus meaning header has been double clicked.
Cheers
Anshul
Hello all
I want to avoid copy paste content and printing from my word document, I have tried with word protection with 'readonly' locking but, still I can able to copy and paste my word file content.
So I go for word macro.
Now I know how to write a macro manually but I want to create it using vb.net and call it.
How can I write macro using VB.NET for a given word file ?
Basically I need to develop program in vb.net where user can browse his word file and I can disable its copy paste facility by using macro.
Using C#
I'm launching Word from my C# application.
//Create a new document from template
Object oTemplatePath = GetTemplateFile();
m_document = m_winword.Documents.Add(ref oTemplatePath, ref missing, ref missing, ref missing);
How to hide the Active Word Document in Window Task Bar? I do not want to hide the application. I only want the taskbar icon not to be visible.
Thank You
MCunha
I'm trying to create a macro that goes throgh each line and makes sure that any line that has an indent of 0 has an indent greater than or equal to the indent of the line before it. If it is not greaterthan or equal to the line before it,
I want the indent to be equal to the previous line.
I've found Selection.Paragraphs.LeftIndent is the code that I need to work with but I'm not good at constructing simple code like this without an example of how to do it. I was thinking a "For each oPara In ActiveDocument.Paragraphs" loop but unsure
on how to actually code it.
Dim oPara As Object For Each Para In .Paragraphs If Para.Paragraphs.LeftIndent = 0 Then get paragraph indent of the previous paragraph If then comparitive indent statment make the current paragraph = to previous Para End If End If Next
Here's an example of what I'm working with. Sorry, it won't let me post a hyperlink. "(dot)" to "."
dl.dropboxusercontent(dot)com/u/22523394/Indent%20Example%20.docx
I am attempting to create a cmd button on a userform in WORD which opens an URL. I need to capture text from a textbox that is entered on the userform and it needs to be placed within the middle of the address line of the URL. I need help in writing the VBA code to capture the data from "txtbox1" to feed into the address line within the URL which is needed when the user clicks on the cmd button. This is for an intranet site over an internet site. Any assistance on this would be greatly appreciated thanks for having this forum to ask for "HELP".
Ddesigns
I am using C# word automation to read through a form created using Microsoft Word. The form contains ActiveX checkbox controls. I am a bit clueless on how to check these fields and have searched high and low for sample code but have come up empty.
Could someone point me in the right direction? Say I have an ActiveX checkbox (called "Check1") in a word form, what kind of code do I need to test if it is checked or not?
Thanks in advance,
Scott Lee
I need to search paragraph by giving paragraph heading text associated with it and to which some heading are set like wdOutlineLevel1, wdOutlineLevel2.
For example:
Feature A
paragraph text- A chip is a major building block of an electronic system such as an ASIC or an FPGA.
I want to find the above paragraph by giving only "Feature A" without iterating on all paragraphs of the document.
I have set "heading 2" for text "Feature A" and "paragraph text-......" is the normal text.
Any help will be appreciable.
Hello all
I have a DOC file with some picture and text in it, I make some settings in doc file, I tick'Print only data from a form' to print only form data, when I take print of Doc file it wont print picture or text (Which is right and expected output)
But if I save same file with DOCX extension and try to print document then it prints pictures (Basically it should show same behavior as DOC file and should not print any thing, just a blank image)
Why this happens for DOCX ? is there any setting for DOCX file ? Please help ?
Thanks in advanced
I am running code on opening of a document to check footer info, and prompt user to update if "incorrect". The last two lines of the Sub are:
ActiveDocument.Saved = False
jjj = MsgBox(ActiveDocument.Name, , ActiveDocument.Saved)
End If
End Sub
The MsgBox shows the name of the doc I opened (Jambalaya.doc) and shows FALSE, as I would expect.
But after clicking OK on the MsgBox, if I go to my Immediate window and type in ?ActiveDocument.Saved, it returns TRUE.
And, when I close the doc, it does not prompt to be saved. Is there some other way I should be setting the doc to 'dirty'?
Thank you,
KePaHa
Hi
I am using the Microsoft Word 14.0 Object Library on VS2010 in a WPF application to export a batch of word documents from a database to PDFs. It is working fine for any normal word document but not for those that have a space at the end of the filename. Example: test .doc, test .docx
I have debugged the code and it reads the file fine but on exporting it, it gives the "The directory is not valid" error. I tried manually exporting a file to PDF with a space at the end of the filename from MS Word and it worked perfectly fine.
The code to open and export a word document:-
var wordApplication = new Microsoft.Office.Interop.Word.Application(); var wordDocument = wordApplication.Documents.Open(documentPath); string[] filePath = documentPath.Split('\\'); string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(documentName); destinationPath = "C:\\Users\\manvir singh\\" + filePath[filePath.Length - 5] + "\\" + filePath[filePath.Length - 4] + "\\" + filePath[filePath.Length - 3] + "\\" + filePath[filePath.Length - 2] + "\\" + fileNameWithoutExtension; if (!Directory.Exists(destinationPath)) { Directory.CreateDirectory(destinationPath); } string pdfPath = destinationPath + "\\" + fileNameWithoutExtension + ".pdf"; wordDocument.ExportAsFixedFormat(pdfPath, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
Can I please be assisted on this?
Thanks
Hi All,
Can anybody show a sample code to display the line number of a text in a MS Word document using C# and Word Interop? For example, I have a document Sample.docx saved in C:\. I would like to search for the word "Everest" in the document. The program should return the line numbers that contain the word "Everest" say, in a listbox. i.e. the listbox would contain all line numbers that contain the word "Everest". Many thanks in advance.
here is the code, when i run it the document can be seen in the rich textbox but it is editable so I want it to be readonly document?
void ImportWord()
Hello,
I have a problem with one of our many clients. We have an "old" software written in VB6.0 that uses Word automation. Since the software runs on various Windows-Plattforms with different Windows- and Office-versions it uses late binding. Usually we have relativly few problems and if we have them, they often happen to all users with a special version or patch level or else happen to more than one customer.
Now I have the situation, that I have only one customer, who uses Office 2013 Home & Business, that has exactly one line of code seemingly not working (but not raising an error either).
The code snippet is as follows:
mDocument.Application.Selection.GoTo wdGoToBookmark, , , Bookmark
mDocument.Application.Selection.SelectRow
If Bookmark = "Anlage7" Then
mDocument.Application.Selection.MoveDown wdLine, 4, wdExtend
MsgBox mDocument.Application.Selection.Text, vbOKOnly, "Debug" 'just to see what's selected
End If
mDocument.Application.Selection.Copy
Problem is the line "mDocument.Application.Selection.MoveDown wdLine, 4, wdExtend", where "mDocument" is declared as "Word.Document". The variable "Bookmark" is set to "Anlage7" externally.
The lines to select are in a table where one "row" internally consists of 5 rows and some fields are merged in some columns. So the first ".SelectRow" selects the actual first row and the ".MoveDown" is supposed to select the rest of the "row".
It is working perfectly well in my various test environments with various Word versions and also with our other customers with various Word versions, even with Word 2013. Only for one customer it doesn't work, there is allways only the first row selected.
I have read, that using the "Selection" might not be the best idea, that "Range" might be better, but the code is working for over 10 years now and the saying is "never touch a running system", isn't it?
Has anyone an idea what could be the problem here? Thanks in advance.
Hi, I am trying to Automate the Word document using vb.net
I am facing problems when i try to define a section, insert section breaks and getting it updated in the table of contents.
I will break down the steps that I am trying to do:
1) Add Multiple sections to word document.
2) Define the Section Heading.
3) Add the text that I want to put under this section.
4) Insert Section Break
5) Define another section, follow steps 2,3,4
6) Update all the Section headings and page numbers in the Table of Contents in my first Page.
Problems I am facing:
1) I cannot add the text under the specific section
2) when there is a Page break or Section break the numbers are not getting updated properly (See the Testing section as numbered below)
For Eg: My Table of Contents/ Sections are numbered in the document as below
1) Introduction
2) Electrical Parts
3) Mechanical Parts
1) Testing
3) I have added a table under section Testing and issue is all the cells inside the table are getting numbered.
4) How to define sub-sections numbered in a sequence
Dim oWord As Word.Application Dim oDoc As Word.Document Dim oTable As Word.Table 'Start Word and open the document template. oWord = CreateObject("Word.Application") oWord.Visible = True oDoc = oWord.Documents.Add Dim oRng As Word.Range = oDoc.Content
In the code below: - I cannot get the text added under the section (oRng.Text is not adding any text to the doc)
'-----------------Define Section-------------------------------------------------- oRng.Text = "Introduction" oRng.Style = Word.WdBuiltinStyle.wdStyleHeading1 oRng.ListFormat.ApplyNumberDefault() oRng.InsertAfter(vbCr) oRng.Collapse(Word.WdCollapseDirection.wdCollapseEnd) oRng.Style = Word.WdBuiltinStyle.wdStyleNormal oRng.Style = Word.WdBuiltinStyle.wdStyleNoteHeading oRng.Text = "This document is to define the specification for Electronic Parts" oRng.InsertBreak(Word.WdBreakType.wdSectionBreakContinuous) oRng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
'--------------Insert Table of Contents--------------------------------------------------------------- With oDoc .TablesOfContents.Add(Range:=oWord.Selection.Range, _ RightAlignPageNumbers:=True, _ UseHeadingStyles:=True, _ IncludePageNumbers:=True, _ AddedStyles:="styleSection", _ UseHyperlinks:=False, _ HidePageNumbersInWeb:=True, _ UseOutlineLevels:=True) .TablesOfContents(1).Range.Font.Name = "Arial Narrow" .TablesOfContents(1).Range.Font.Size = 11 .TablesOfContents(1).TabLeader = Word.WdTabLeader.wdTabLeaderDots .TablesOfContents.Format = Word.WdTocFormat.wdTOCSimple End With 'Page Break after Table of Contents oWord.Selection.InsertBreak() 'Update Table of Contents oDoc.TablesOfContents(1).Update() oDoc.TablesOfContents(1).UpdatePageNumbers()
This is how it is seen in the document: TOC is not getting updated properly
1..................................................................................................1
2 Introduction..............................................................................2
3 Electrical Parts..........................................................................3
4 Mechanical Parts.......................................................................4
1 Testing......................................................................................5
Any help on this to get it sorted out would be great and much appreciated.
I am using Word's WindowSelectionChange event to tell me when the user has modified the content of a specific area of the active document. At this point, the code in my VSTO global add-in performs a series of steps such as checking various ranges and updating content in the document's header. The problem I am seeing is that an hourglass is shown during this processing, and Word 2013 has a definite performance lag when compared against Word 2010.
Other than the usual things (i.e., optimizing use of Word objects, using Range instead of Selection object whenever possible, suppressing ScreenUpdating, discreet use of DoEvents, etc.), I am looking for ideas on how I can make this lag less obvious. I have heard of the BackGroundWorker class but I do not know much about it... Or, would that possibly lead to problems if called from within a Word add-in's WindowSelectionChange event (any maybe it is not even possible)?
Any tips or suggestions will be greatly appreciated.
Hello Everyone,
I have a very large wordfile. I would like to parse and get Locations of for example Italic Highlightingand Footnotes. Does anybody have a good example how to get started on this?
I would appreciate any help greatly, kind blessings
Andreas Bolliger
We've got an Office add-in compiled against the Office 2013 PIAs. We have a "graph template" doc file that has an embedded Excel chart that is the correct size. The add-in adds a button which allows the user to insert the graph into
their own Word document. It does this by opening the "Graph Templates.doc" file, accessing the graph via the InlineShapes collection, copies the graph to the clipboard and then does a PasteSpecial into the target document. The result
is a graph that is only a fraction of the height of the original graph. I've reduced the code down to the following (VB.NET in VS2008).
The code relies on two doc files and the template file must be in the location specified in the code (or edit the path in the code).
Graph Templates.doc (I guess I can't have links until my account is verified? Let me know and I will email them.)
TestTemplate.doc
These documents are opened in compatibility mode, and I thought perhaps it may have something to do with the bad behavior, but after up-converting I still had the same behavior. I've pretty much run out of ideas, so any help would be appreciated.
Thanks,
Terry
PS - How do I go about getting my account "verified" so I can post images and links?
Code below:
Private Sub InsertGraphToReport2() Dim graph_template_full_name As String Dim doc As Word.Document Dim inline_shape As Word.InlineShape Dim work_book As Excel.Workbook Dim current_selection As Word.Selection Dim docs As Word.Documents Dim temporary_file As String current_selection = m_WordApp.Selection graph_template_full_name = "C:\ProgramData\Test\Graph Templates.doc" If (File.Exists(Utility.GetStandardPath(graph_template_full_name)) = False) Then Exit Sub End If temporary_file = graph_template_full_name.Substring(0, graph_template_full_name.LastIndexOf(".")) & ".tmp" docs = m_WordApp.Documents doc = docs.Add(Template:=graph_template_full_name.ToString(), Visible:=False) inline_shape = doc.InlineShapes.Item(1) inline_shape.OLEFormat.DoVerb(Word.WdOLEVerb.wdOLEVerbHide) work_book = CType(inline_shape.OLEFormat.Object, Excel.Workbook) inline_shape.Width = doc.PageSetup.PageWidth - doc.PageSetup.RightMargin - doc.PageSetup.LeftMargin inline_shape.Height = inline_shape.Height + 1 doc.SaveAs(temporary_file.ToString()) inline_shape.Select() doc.Application.Selection.Copy() current_selection.PasteSpecial(Link:=False, DataType:=Word.WdPasteDataType.wdPasteOLEObject, _ Placement:=Word.WdOLEPlacement.wdInLine, DisplayAsIcon:=False) doc.Close(SaveChanges:=Word.WdSaveOptions.wdDoNotSaveChanges, RouteDocument:=False) CleanUp(work_book) CleanUp(current_selection) CleanUp(inline_shape) CleanUp(doc) CleanUp(docs) Clipboard.SetDataObject("") GC.WaitForPendingFinalizers() GC.Collect() File.Delete("C:\ProgramData\Test\Graph Templates.tmp") End Sub Sub CleanUp(ByVal obj As Object) If (obj Is Nothing) Then Exit Sub End If Try System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) Catch Finally obj = Nothing End Try End Sub