473,395 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

C# Running a Word Macro messes up Word Setting

I am trying to develop a C# program to fill in the blanks in a Word Form. Everything works beautifully while the program is running.

I had to go in to fix some links on our Web Site a couple of days later and found any Word Document containing links now shows the code instead of the link. i.e. {HYPERLINK "Executive%20Summary%20for%20CSI.doc"} instead of CSI. I have traced this error down to my program but don't know what is causing it.

The code is:

public string StartupPath = "c:\\Documents and Settings\\Kym\\My Documents\\";
// Object for missing (or optional) arguments.
object oMissing = System.Reflection.Missing.Value;

public void WordMacro()
{
// Create an instance of Word, make it visible.
// and open 971 Form.doc.
Word.ApplicationClass oWord = new Word.ApplicationClass();
oWord.Visible = true;
Word.Documents oDocs = oWord.Documents;
object oFile = StartupPath + "971 Form.doc";

//if the Microsoft Word 11.0 Object Library is referenced
Word._Document oDoc = oDocs.Open(ref oFile, ref oMissing,
ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
RunMacro (oWord, new Object[] {"MergeDocument"});

}

private void RunMacro(object oApp, object[] oRunArgs)
{
oApp.GetType().InvokeMember("Run",
System.Reflection.BindingFlags.Default |
System.Reflection.BindingFlags.InvokeMethod,
null, oApp, oRunArgs);

}

The code for the Macro in Word is:

Sub MergeDocument()
'
' MergeDocument Macro
' Macro recorded 9/17/2007 by h0014742
'
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
.LastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
End With
.Execute Pause:=False
End With
End Sub

When finished, this program is supposed to be distributed company wide. I can't have it messing up other people's Word Program. Can you please help me?
Sep 26 '07 #1
0 1281

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: bekil | last post by:
Thanks for your suggestion Murray Jack. I also record macro while doing it manually in word then I edit the macro to see the required code. Firstly I am creating a blank page. Secondly I go to...
7
by: Kenneth_J | last post by:
Hey everyone, I just started doin some work with access and vba, and don't know much about it yet...any help would be much appreciated. My goal is to create a form in word that can be filled...
0
by: DHRRush | last post by:
When working in Access 2000, if I'm in the code editor and want to run or step through code to debug or test, instead of the code running (whether from beginning of sub, or anywhere in the sub), I...
3
by: Martin Austin | last post by:
Here's my problem. I'm launching an MS Word object on a Notes document Postopen event. The script kicks off a macro that saves the Word document to a temporary file every n minutes (backup of key...
5
by: Mason | last post by:
I'm having some problems converting VBA for Word 2000 to code that VB.Net understands. I recorded a macro in Word to add numbering (a. b. c.) to my paragraphs. I managed to translate quite a bit...
4
by: Rob | last post by:
Here is my issue: I am trying to load word through vb.net code behind an ASP.NET webform. I know it is possible to use the Automation and COM classes because a co-worker has it working on his...
5
by: krbyxtrm | last post by:
Hi is there a way to 'manage' function execution using macros? #define MY_CALL_MACRO(MacroName) { g_MacroStack.push_back(MacroName); <some code here...>} such that when i use the...
6
by: Eric Layman | last post by:
Hi, I have fields from textareas. With a click of a button, php is able to grab these fields and by using header(), convert the output to Ms Word doc. But the outcome of the word doc...
1
by: sandyt57 | last post by:
I do Tech Support but do not know Visual Basic programming. In order to resolve a work process issue for one of our depts I need a macro that can do the following. I tried to create a macro in Word...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.