|
-
Jun 21st, 2007, 07:39 AM
#1
Thread Starter
Fanatic Member
Visual Studio to Word
Can I have a user fill out some textboxes and have it generate a word doc based on a word template? What I want is I have a title page with two are areas, Title and Subtitle and I would like the user to fill out the 2 textboxes and then once they click the button it generates the word document where I have predetermined the text location.
-
Jun 21st, 2007, 08:48 AM
#2
Re: Visual Studio to Word
Hey Beast,
You can do this with Visual Studio Tools for Office.
Hope this helps.
-
Jun 21st, 2007, 10:53 AM
#3
Re: Visual Studio to Word
Or check out my Office FAQ (link in my signature).
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 21st, 2007, 12:01 PM
#4
Thread Starter
Fanatic Member
Re: Visual Studio to Word
I had the following code working for opening a word document. However, I tried adding in Office XP PIA's and since then it has not worked. I uninstalled all the PIA's and still not working. I get this error:
Unable to cast COM object of type 'Word.ApplicationClass' to interface type 'Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
nmadd - The clients machines are all XP - will those Visual Studio Tools for Office work with XP, it looks like they are for 2003.
Here is the code that was working:
Code:
private void button6_Click(object sender, EventArgs e)
{
object fileName = "M:\\Public\\SOPs\\CFSCE SOPS\\English\\300 - Training Support\\302_Annex H.doc";
object readOnly = false;
Word.ApplicationClass WordApp = new Word.ApplicationClass();
object isVisible = true;
object missing = System.Reflection.Missing.Value;
WordApp.Visible = true;
Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
aDoc.Activate();
}
-
Jun 21st, 2007, 12:06 PM
#5
Thread Starter
Fanatic Member
Re: Visual Studio to Word
I just tried my solution on a second machine loaded with VS2005 and it still works on it. So, I am guessing trying to get those PIA"s to work has buggered up my VS. Is there a way to reload the Word references in VS, not my solution, I have tried that.
-
Jun 22nd, 2007, 04:04 AM
#6
Re: Visual Studio to Word
You should be using Word.Application and not he Word.ApplicationClass.
How are you deploying your app? You will need the PIAs for whatever version of Office you are using/supporting if using the .Interop class. Otherwise completely using Late Binding and Reflection is what you will have to use.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 22nd, 2007, 04:17 AM
#7
Re: Visual Studio to Word
please explain both of those terms or link to a doc you have explained them in? I am pretty good at coding inside word/access/excel but i suck at controlling them from vb
-
Jun 22nd, 2007, 04:23 AM
#8
Re: Visual Studio to Word
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 22nd, 2007, 04:56 AM
#9
Re: Visual Studio to Word
Late Binding and Reflection
-
Jun 22nd, 2007, 07:16 AM
#10
Thread Starter
Fanatic Member
Re: Visual Studio to Word
The only reason I started down this PIA road was because I checked MS and then had examples but you needed to install PIA's. I am guessing I just went down a wrong road. Obviously, I need to play with some of your links first.
I changed the statement to:
Code:
Word.Application WordApp = new Word.Application();
and still get this error:
Unable to cast COM object of type 'Word.ApplicationClass' to interface type 'Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
Last edited by Beast777; Jun 22nd, 2007 at 07:20 AM.
-
Jun 22nd, 2007, 07:30 AM
#11
Thread Starter
Fanatic Member
Re: Visual Studio to Word
I just looked through your link, and for Word, it looks like most of the examples are for VB6. I am currently trying to work in C# VS2005 but I know VB 2003 better. Do you have an example to open a word doc in C# VS2003 or VS2005.
-
Jun 22nd, 2007, 07:40 AM
#12
Thread Starter
Fanatic Member
Re: Visual Studio to Word
I had a look at the Visual Studio Tools for Office and it is for Office 2003. We are going to migrate there in 6 weeks but this project cannot wait that long.
-
Jun 23rd, 2007, 02:09 PM
#13
Re: Visual Studio to Word
Late Binding and Reflection to Automate an Office app in C#:
http://vbforums.com/showpost.php?p=2580243&postcount=2
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 23rd, 2007, 07:51 PM
#14
Re: Visual Studio to Word
Not sure how relevant this is in the current discussion but there are different PIA for the different versions of the installed office. Try to find those that are for the version you have on your machines.
-
Jun 24th, 2007, 02:32 PM
#15
Re: Visual Studio to Word
Yes, there are only PIAs for 2002, 2003 and 2007. If you have a previous version of Office then you need to use Late Binding. Also, you need to create separate setups for each version you are supporting when using PIAs.
Link in my signature
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|