[RESOLVED] AddPicture from Application.StartupPath
Hi
This is maybe very simple, but need some advice on the path. In my app I add a picture to a excel sheet, and it's working fine but I don't want the file in ex. c:. It should be in the Application.StartupPath, therefore I used this:
Code:
xlWorkSheet.Shapes.AddPicture(Application.StartupPath, & "\Test.JPG", _
Microsoft.Office.Core.MsoTriState.msoFalse, _
Microsoft.Office.Core.MsoTriState.msoCTrue, 2, 2, 30, 30)
but with this I get "expression expected" with the &. If I use a path "c:\Test.jpg", it work's.
Re: AddPicture from Application.StartupPath
You have a comma after Application.StartupPath
Re: AddPicture from Application.StartupPath
Hi
Thank's. But now I get file is a none shared member. Requires an object reference.
Re: AddPicture from Application.StartupPath
I'm sure there's a better way of doing this, but this seams to work.
Code:
Private Function AppPath() As String
Return System.Windows.Forms.Application.StartupPath
End Function
xlWorkSheet.Shapes.AddPicture(AppPath & "\Test.JPG", _
Microsoft.Office.Core.MsoTriState.msoFalse, _
Microsoft.Office.Core.MsoTriState.msoCTrue, 2, 2, 30, 30)
Re: [RESOLVED] AddPicture from Application.StartupPath
if that works there is no reason why this shouldn't work
Code:
xlWorkSheet.Shapes.AddPicture(System.Windows.Forms.Application.StartupPath & "\Test.JPG", _
Microsoft.Office.Core.MsoTriState.msoFalse, _
Microsoft.Office.Core.MsoTriState.msoCTrue, 2, 2, 30, 30)
Re: [RESOLVED] AddPicture from Application.StartupPath
Absolute true. If anyone is lazy, they don't have to type the whole string over and over again. Like me ;)
Re: [RESOLVED] AddPicture from Application.StartupPath
well if this code is in a project that has a project level import of system.windows.forms (like winform apps do by default), you shouldn't have to qualify it with System.Windows.Forms, you can just call application.startuppath.
If this code is not in a project that has system.windows.forms as a project level imports, you could add it, or you could just add an imports statement to the top of the code module, and then you would be able to use just application.startuppath there as well.
If you are writing
Re: [RESOLVED] AddPicture from Application.StartupPath
Of course you're right, but since I'm a self learning "programmer" fundamental things is sometimes overseen. My solutions of problems is quite often trial and error. Learning by doing. Thank's for taking your time.