Can you use a macro to insert a graphic? Or apply a template?

T

TychaBrahe

We get a data export as a .csv that automatically opens Excel. I've
written/recorded a macro that sets column width, adds header rows and a
footer, changes fonts, and whatnot.

One thing I cannot make it do is insert a graphic of our logo. Any ideas?

In addition to having the graphic as a separate, importable file, I have it
in a template. The problem is that is seems the template only works for new
spreadsheets. It doesn't seem that you can apply it to an open worksheet the
way you can with a style in Word.

Is this graphic thing workable at all?
 
L

Luke M

You should be able to use something like the following:

ActiveSheet.Pictures.Insert( _
"C:\Documents and Settings\Documents\My Pictures\Sample
Pictures\Sunset.jpg" _
).Select

Just change the file location to match your logo. You can then record a
macro of you adjusting size, if necessary.
 
D

Dave Peterson

How are you importing the .csv data?

If you're using file|open, you could open the .csv file and then do all the
formatting, then create a new workbook based on your template, then copy the
..csv data into that workbook (first sheet???) and close the .csv file without
saving.

With no testing at all:

Dim CSVWks as worksheet
dim RptWks as worksheet

set csvwks = Workbooks.Open(Filename:="yourcsvfilename.csv").worksheets(1)

set rptwks _
= workbooks.add(Template:="C:\yourpath\myfile.xlt").worksheets("sheet1")

'do the formatting work in csvwks if you want.
'or wait to do it in the template worksheet

csvwks.cells.copy _
destination:=rptwks.range("A1")

csvwks.parent.close savechanges:=false

============
If you're importing your csv data via Data|Import External Data, you should be
able to open the template file and import it directly onto the sheet you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top