Results 1 to 3 of 3

Thread: Insert picture in Excel using VBA

Hybrid View

  1. #1

    Thread Starter
    Lively Member yanty's Avatar
    Join Date
    Nov 2005
    Location
    Singapore
    Posts
    83

    Resolved Insert picture in Excel using VBA

    Hi all.

    I can insert picture to the header of my excel sheet using the below codes

    VB Code:
    1. Dim oSW As Excel.Worksheet
    2. 'Add picture at left header
    3.     Set oSW = Worksheets(1)
    4.     With oSW.PageSetup.LeftHeaderPicture
    5.     .FileName = (App.Path & "/Pic.jpg")
    6.     .Height = 50
    7.     End with

    But the problem is my data on the excel sheet will cover part of the picture in the header. (See attached image)Why is this so that data can be mixed with header of the worksheet? any solutions?
    Attached Images Attached Images  
    Last edited by yanty; Feb 21st, 2006 at 04:24 AM.
    I think I'm starting to like programming, but I'm still far from good

  2. #2

    Thread Starter
    Lively Member yanty's Avatar
    Join Date
    Nov 2005
    Location
    Singapore
    Posts
    83

    Lightbulb Re: Insert picture in Excel using VBA

    I think I've found the solution, The worksheet looks okay now. Hehe.

    VB Code:
    1. Dim oSW As Excel.Worksheet
    2. Set oSW = Worksheets(1)
    3.     With oSW.PageSetup.LeftHeaderPicture
    4.     .FileName = (App.Path & "/Pic.jpg")
    5.     .Height = 50
    6.         End With
    7.     oSW.PageSetup.LeftHeader = "&G"
    8.     oSW.PageSetup.HeaderMargin = 30
    9.     oSW.PageSetup.TopMargin = 90
    I think I'm starting to like programming, but I'm still far from good

  3. #3

    Thread Starter
    Lively Member yanty's Avatar
    Join Date
    Nov 2005
    Location
    Singapore
    Posts
    83

    Re: Insert picture in Excel using VBA

    I just found one problem. When i click on the button that exports my database data to excel, it worked at first. Excel opens and data from database is exported, even the header works. But if I close the excel sheet and click on the button again, error occurs and points to Set oSW = Worksheets(1)

    The notice state "Method 'Worksheets' of object '_Global' failed". Did I set teh oSW wrongly?
    I think I'm starting to like programming, but I'm still far from good

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