I want to use a form with buttons on to link to open excel files or word documents. Therefore the files need to be available to the program which must run from a CD. (need the CD to be in always).
I have added the files to resources and see them in the solution explorer bin folder. I have also made them "copy always" in the file properties. See path of attendance register in sloution explorer.
Test1/bin/Debug/resourses/Attendance register. doc.
I need the code for the buttons. I know it needs to be relative path but thats as far as me knowing goes.
I am using visual studio 2005 (programming in VB) , windows7, office 2007 but save files as 2003.
Urgently need help so that I can move on, battling for 3 weeks no luck!!!
I have attached a snip from solution explorer, is it?? see attached file
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'If Me.OpenFileDialog1.ShowDialog() = DialogResult.OK Then
'Dim fileName As Object = OpenFileDialog1.FileName
Dim fileName As Object = "C:\Users\admin\Documents\Visual Studio 2005\Projects\Test1\Test1\bin\Debug\Resources\Attendance Register.doc"
'Dim readOnly as Object = False
Dim isVisible As Object = True
Dim missing As Object = System.Reflection.Missing.Value
WordApp.Visible = True
Dim aDoc As Microsoft.Office.Interop.Word.Document
aDoc = WordApp.Documents.Open(fileName, , False, False, , , True)
Me.Hide()
'End If
End Sub
Thats what I've been trying - I know its wrong but at least you can see what I've done
The path you gave "C:\Users\admin\Documents\Visual Studio 2005\Projects\Test1\Test1\bin\Debug" is the development path. I would be very surprised if the path was the same on the other machine.
And even the application is installed in My Documents ("C:\Users\admin\Documents") on the test machine, this path can change name between different versions of Windows.
Try with Path.Combine(Application.StartupPath , "Resources\Attendance Register.doc"), which is a reference to where the application is installed.
Jacques Bourgeois
JBFI
http://www3.sympatico.ca/jbfi/homeus.htm