Results 1 to 8 of 8

Thread: [RESOLVED] AddPicture from Application.StartupPath

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Resolved [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.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: AddPicture from Application.StartupPath

    You have a comma after Application.StartupPath

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: AddPicture from Application.StartupPath

    Hi
    Thank's. But now I get file is a none shared member. Requires an object reference.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    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)

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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)

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    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

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width