Click here to Skip to main content
13,403,376 members (52,591 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I would like to populate a word document using a windows form (i.e. have a user enter text into a textbox in windows form (i.e. textbox1) and then click submit and have the application open a word document that I have created and place the users text into a form field using a bookmark (i.e. bookmark1).

got below code

Imports Microsoft.Office.Interop
Public Class Form1
    Dim wordapp As Word.ApplicationClass
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'open word document
        wordapp = New Word.Application
        Dim objdoc As Word.Document = wordapp.Documents.Open("c:\test")
        'go to bookmark
        wordapp.Selection.GoTo(What:=Word.WdGoToItem.wdGoToBookmark, Name:="Bookmark_Name")
        ' enter text from textbox
        'make document visible
        wordapp.Visible = True
    End Sub
End Class

I am using c#. I want to write code in c#.

Please help.
Posted 27-Sep-12 23:39pm
Updated 28-Sep-12 8:48am
Richard MacCutchan 28-Sep-12 9:38am
And your question is?
ryanb31 28-Sep-12 14:27pm
What is the question? Also, record a macro doing what you want and that will give you a good starting point.
Marcus Kramer 28-Sep-12 15:50pm
if you want the code in C#, go ahead and translate the VB code you have. That seems like a pretty simple thing.

You helped me to understand what this question is about, thank you.
If this is just about code translation, I suggested some good ways to translate automatically, some on-line and a really comprehensive off-line solution. Please see my answer.

hasbina 29-Sep-12 7:29am
got it...

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

In my past answers, I suggested some really good ways to translate from VB.BET to C# and visa versa automatically. There are both on-like solution and a really comprehensive off-line solution:
COde Line Interpretatio of C# to VB.NET[^],
Need to convert vb code to c#[^],
FixedPage to ContentPage convert c# code into[^].

Ron Beyer 3-Aug-13 23:00pm
How did you find this? Its almost a year old...
What difference does it make? A problem is a problem, it is actual and still not resolved.
Sometimes I see such posts that makes me asking: "what else this person posted, I wonder?"... :-) I was looking at some fresh post, and then...
Ron Beyer 3-Aug-13 23:11pm
No difference at all, just curious how you came across it, I usually only go back a page or two but this must have been pretty deep :)
I answered. It's not deep if you go back not by the list of all questions, but by the list of some member's posts.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.1802120.2 | Last Updated 3 Aug 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100