Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Excel Macro: Resize A Picture And Insert Into Spreadsheet

Hi, I'm new to excel macro programming and would like a macros that can iterate through a directory with large jpegs such as:


and create a thumbnail of each large image and save it to

c: humbs

The most important is the resized thumbnail MUST BE IN PROPORTION with the origianl image, so "keep aspect ratio".

Any help would be appreciated, thank you!!

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Using VB Code Macro To Insert ComboBoxes In Spreadsheet?
I am writing a macro that creates a new worksheet and I would like to add some combo boxes into the spreadsheet. My problem is this: what is the code to add a combo box to the spreadsheet ? I would like to have the equivalent of the forms toolbar adding the following to a cell.

=EMBED("MSForms.ComboBox.1", "")

I assume its possible, but I just haven't been able to find out how. Thanks so much for any help in advance.

Auto Resize Picture After Insert
I created a macro to insert picture and after insert the picture will auto resize and fit into my range (BO1).
Please advice

Dim x As Variant

x = Application.GetOpenFilename("Pictures (*.jpg;*.bmp;*.gif), *.jpg;*.bmp", , "Select Picture")
If x = False Then Exit Sub 'no file selected
Set mypic = ActiveSheet.Pictures.Insert(x)
With mypic
.Left = Range("BO1").Left
.Top = Range("BO1").Top

End With

Excel Macro Opening Spreadsheet
I've developed a VB 6 app that gets data about our department every 15 minutes. There is an application here that monitors our phone systems. I have it run reports every 15 minutes. These reports are saved as Excel spreadsheets. I have a macro in Access that imports the spreadsheets into Access, then I populate my app using ADO and Access as the backend. Hope I didn't lose you with that. Now the problem: occasionally, when the macro runs in Access, it will open the spreadsheet being imported on my screen. This usually happens when I have Excel open for something else, which is quite frequently, since getting data and creating spreadsheets is a large part of my job. Then my app will hang because it can't import an open spreadsheet. Sometimes, I don't even realize that the spreadsheet is open unless I open the Task Manager and see it running. Is there a way to import a spreadsheet without actually opening it? I've looked, but didn't see a setting for something like open minimized, then close the spreadsheet after it's imported.

Macro: Copying Rows To Another Excel Spreadsheet?

New to the board.

I am current writing some VB code for some Excel macros for work, but I have never learnt VB so I am picking it up as I go along.

I am trying to copy rows of a spreadsheet to other spreadsheets based on a cell condition.

I know the current code I have...

If Cells(x, 5).Value = "8" Then
Cells(x, 1).EntireRow.Copy
Sheets("Sheet1").Cells(a, 1).PasteSpecial
a = a + 1
End If to copy rows to another sheet in the same spreadsheet, but how would I copy to Sheet1 of another spreadsheet, called "Test.xls", say?

Any help would be appreciated.


Manipulating An Open Excel Spreadsheet From An Outlook Macro
I'm a VBA newbie, and am wanting a little help. I know how to open a spreadsheet and manipulate it. I know how to manipulate a spreadsheet from an excel macro, but I can't seem to figure out how to manipulate an open spreadsheet from Outlook (it doesn't help that I don't seem to have the help docs for the object libraries).

Anyway, I'm trying to get a bunch of strings from e-mails in Outlook (which I've done already) and send them to an open spreadsheet using a macro.

Here's what I'm trying, but, of course, it doesn't work:

Dim exlApp As Excel.Application
Dim exlWkbk As Excel.Workbook
Dim exlSheet As Excel.Worksheet

Set exlApp = GetObject(, "Excel.Application")
exlWkbk = exlApp.Workbooks("test.xls").Activate
exlSheet = exlWkbk.Worksheets("SHEET1")
exlSheet.Cells(1, 1) = "Test Successful"

When I attempt to run the macro, "Activate" is highlighted, and an error message reads, "Object or Function Expected".

What do I need to do here?

RESOLVED:Checking A Checkbox On An Excel Spreadsheet From A VB Macro
I don't seem to be able to refer to the checkbox's value from VB. What is the proper syntax/name when referring to it from VBA?

Edited by - jeffers on 12/9/2004 7:29:44 AM

Read A Text File And Insert Into Excel Spreadsheet
I have this following requirement:

From VB, I have to read data from a flat file (*.txt) where everything within the file is delimited by semicolon and then insert that data in to a Excel spreadsheet. Please let me know how can that be done in VB 6.0. A sample code would be good for understanding.

Thanks in advance !!!

How Do I Insert A DtPicker (or Equivalent) Into An Excel Spreadsheet Cell?

As per the subject, how do I insert a dtPicker (or nearest equivalent) into an Excel spreadsheet cell so that its 'combo' appears in the cell and if it is clicked on and a date selected, that date is displayed in the cell?


Insert Macro In Excel From Vb
Hi all

Can anyone give some ideas or tutorials on how to insert a macro into excell from vb without making the excel app visible.

I want to build a report with excell using data from vb. I want the macro to format the excel worksheet to look like the report i want to print.

Any ideas or links to tutorial would be grteatly appreciated.

Thanks in advance

Insert An Excel Macro From VB
Hi all !!

Iīm creating a new xls file. I need to insert a macro on it from vb before saving and closing the file.

Hereīs how I create the object:

Dim X as Object
Set X = CreateObject("Excel.Sheet")

HELP !!!
Any ideas???

Insert A Macro From Vb6 Into Word Or Excel
hi there,

i would like to know if i can insert a piece of vba code ,which is in my vb6 app, into Word and Excel into a new marco or something and if that is possible, how i've got to do that.


Select And Delete A Picture Located On Excel Spreadsheet In Visual Basic 6
Can anyone help please...

I have a series of simple diagrams, i.e. triangle, square, circle etc.. These are separate .gif files located in a certain directory.

I have a macro which inserts one of these files, say the triangle, as a 'picture' into an excel spreadsheet.

Within the spreadsheet I can specify a new picture, say the square, and the macro will insert the appropriate file accordingly.

At present when I change from the triangle to the square, the triangle remains where it is and the square is located on top of the triangle.
Any subsequent changes are located on top of the previous picture, so I end up with several picture on top of each other.

Each time a picture is inserted into the spreadsheet, excel automatically creates a new number for it, i.e. picture 1, picture 2, picture 3, etc. and if I select and delete them manually, the next picture inserted takes the next number i.e. picture 4 and so on (currently picture 23 !)

I want my macro to be able to delete previous pictures so that after making a change, only one picture remains on the spreadsheet.

My code so far is as follows:

Code:Sub GetDrawing()
    Sheets("Single Site Model").Select 'This is the spreadsheet
    selecteddrawing = Worksheets("Single Site Model").Cells(1, 7) 'This is where I specify a new drawing (i.e. Triangle, Square, etc.)
    drawingstring = selecteddrawing & ".gif"
    thedrawing = "C:Documents and SettingsMy DocumentsMy Pictures" & drawingstring 'This is the path of the drawing file
    Range("A7").Select 'This is where the drawing will be located
    Range("a6").Select 'This is the end position for the cursor

End Sub

Can you please advise me of the code required to select individual pictures and/or select all existing pictures in an excel spreadsheet, so that I can get the macro to delete them before a new picture is inserted.

Thank you in anticipation

Regards, Mike


Writing A Macro In VB To Insert A Chart In Excel
I am working on an excel spreadsheet (attached) and am having a problem with the "Insert Chart" Macro I am trying to create. I'm not really too sure how to approach this but if you look at the code I've written so far you may be able to tell me if I'm on the right track or not. The other macros in the sheet all work OK. When I run "insert new mechanic" and add data I need the chart to reflect this. Also I don't need the data in the second column ("B" ) to be included in the chart. As you can see I've fiddled around with the coding a fair bit but as yet have not come up with a solution. I would appreciate any help. Please see attachment.

Excel Macro To Insert Formula For Variable File First Sheet
I built a macro that loops through all the file names in a folder.
I wanted to then check in cell c7 of each file to see what the content was with out opening the file. I was unable to accomplish this, so I went to plan 2. I want to place a formula on a spread sheet that will bring in the number from cell c7 on the first worksheet. The reason I went this rout is time. When you open and close files the macro takes too much time to run. My formula below works as long as the first sheet in each workbook is sheet 1 the problem is most are not they vary in name. How can I replace sheet1 in my code to pull any 1st worksheet name?

Formula1 = "='H:Mo[" & MyFile & "]Sheet1'!C7"

Can We Insert A Picture Into Excel?
I wanna insert a picture into cells(1,1) and I created a macro like this:
When I run the macro, the dialog pop up..then I don't know how to code after that...Can anyone Help me Please!

Insert Picture In Excel

I have a Form with a PictureBox. How can I insert this picture from a PictureBox in the Excel sheet?

Do I have to save it as a file and then insert it using ActiveSheet.Picture.Insert? Or there is a simplier way of doing it?


Insert Picture In Excel From VB

I'm trying to insert a picture into a header of Excel, but I can't seem to make it happen. Anyone has any suggestions?


Visual Basic Macro - Create Email Insert Data From Excel
I am looking for a solution to do the following (and have searched and searched and have not found an answer.)

I need to have a macro that generates an outlook email from data listed in an excel spreadsheet. Not only will this macro need to read data from a column containing email addresses (a list of recipients), it will need to insert excel data listed in different workbooks of a single spreadsheet. The data that needs to be inserted will vary from receipient to recipient - i.e. will not be the same length or content for each email.

I need to know if this will be possible - I do have a simple, generic macro listed below that will create a form letter - but I am not certain if this can be changed to allow a. different excel content and b. email support. Any help would be very much appreciated.


Sub Do_It_All_Form_Letter()
Dim word As Object

Set word = CreateObject("word.basic") 'creates the word object

With word
.AppShow ' Makes Word Visible

'Sends keystrokes to the Open Worksheet dialog box
SendKeys "{TAB}{TAB}{TAB}{ENTER}"

'Opens the Microsoft Excel file
.FileOpen Name:="c: estdata.xls"

'Saves the file as a Microsoft Word document
.FileSaveAs Name:="c: estdata.doc", Format:=0

.FileClose 'Closes the file
.FileNewDefault ' Opens up blank Word document

'Makes the active window a main document
.MailMergeMainDocumentType 0

'Open the data source
.MailMergeOpenDataSource Name:="c: estdata.doc", _

'Activates the mail merge main document

'The following Insert commands place text into the Word
'document. You could change these commands to place any text in
'the document. This example uses a typical business letter

.Insert "3454 Blindside St." 'Inserts a string
.InsertPara 'Inserts a carriage return
.Insert "Columbia, GA 23287"

'the mergefields are the same as the column headings in the Excel
.InsertMergeField MergeField:="NAME"
.InsertMergeField MergeField:="ADDRESS"
.InsertMergeField MergeField:="CITY"
.Insert ", "
.InsertMergeField MergeField:="STATE"
.Insert " "
.InsertMergeField MergeField:="ZIP_CODE"
.Insert "Dear "
.InsertMergeField MergeField:="NAME"
.Insert ","
.Insert "Thank You For Your Support."
.Insert "Sincerely,"
.Insert "John M. Doe"
.MailMergeToDoc 'Merges data records with the main document
' Saves the active document with the specified name
.FileSaveAs Name:="c:letters.doc"

End With

Set word = Nothing 'clears the object variable

End Sub

Remove A Picture In Excel, Using A Macro
I have created a macro in Excel that inserts a bunch of pictures onto a spreadsheet, now my problem is I want to do the complete opposite, and create a macro that removes the pictures I have just inserted. Here is how I am loading the pictures:


Thanks in advance..

Insert Picture Into An Excel File.
Hi there,
Pls let me know how to insert a picture into an Excel file
Thank you very much.

How To Use The Insert Picture Form From Excel
I want to use the insert picture form which appear when you click the main toolbarinsertpicturefrom files. and then get the path of the file


[VB-Excel] Script To Insert Picture Varible...
Hey Im new to VB coding so can some one please help me script this code...

I got an work book where on Sheet 1 theres a list of items with a code for each item. E.g. 10214 | Sony TV

On Sheet 2 i will select a product which can be the sony TV and the code will also appear. But when i select the product i want VB to display a picture of the item. So everytime i change the item on the sheet the picture should be changed.

I will store all pictures on one folder like C:Pic10214

So the VB should collect the code in "10214" from Sheet 2 and search for that pic which is named same as the code "10214" and Display it in Sheet 2. For example in Cell C5

Can anyone help Please?

Thanks In Advance.
...Any Ideas?

Using String Variables To Insert Picture In Excel (in VB Script)
Please can somebody tell me why the following statement keeps bringing up an error, why won't it work?

I am trying to load a picture into Excel using a VB macro with a string variable as the filename
e.g. sFilename = "c:myfilesimage1.jpg".


The error is:

Unable to get the Insert property of the Pictures class.

To my mind, it's as though it can't get the value of sFilename.
A MsgBox can but apparently this cannot.

I cannot hard code the filename i.e.


even though this works because I want to load in several pictures with different names as part of a loop.

sFilename is actually made up of a hard coded path and the filename for each image is plucked from different a cell on the spreadsheet.

I would be eternally grateful if someone could just tell me how to get this simple task to work!


Word Macro Insert File/ Append Table Macro Issue.

I was wondering if someone could help me with this problem...

When I use the following code to insert a table (from an external file), the table that is inserted does not append to the table in first document (which is what I want it to do)...

Sub Macro1()

Selection.Collapse Direction:=wdCollapseEnd
Selection.InsertFile FileName:="m:cat.DOC", Link:=True

End Sub

Would anyone know how I can make the contents of this file append to the table in the first document?

Thanks so much in advance,


Spreadsheet Macro Help?
i have two questions.

1) i have created a form (vba written form) in excel and want to make it so that you can press a button on a toolbar and it will start the form up.

2) how do i attach the form to the WORKSHEET im using. because once in a test it was attached to the normal template on my computer and not to the worksheet.

Need To Insert Row In Spreadsheet Using VB
Hello All,
 I am new to excel programming but now am trying to insert row in spreadsheet using VBA programming.I am using Access 97.How can
I insert any row in the spreadhsheet using VBA code.I actually want
to add header and footer to the spreadsheet and also may need to
insert row in between the sheet.Please anyone can paste the code
snippet as I am new to syntax.
Thanks in advance.

Have Macro Run When Spreadsheet Is Opened
Hi all. I am trying to have my macro run as soon as my spreadsheet opens but I can't seem to find the correct syntax to do it. I've done it before but it was a few years ago and I can't remember how I did it. I used the help and found a command I thought would help but I couldn't get it to work. Any ideas?

Thanks, Dave

Want Macro To Run When I Open Spreadsheet.
Hi, this question must seem really easy to most of you but im new to VB. I have sheets in my spreadsheet that i dont want users to see so i want it to go to a specific sheet when it is opened. At the moment it goes to whatever page i saved it on. If i forget to save on the right page users may access pages i dont want them to see. How can i make it open on the 'Main Menu' sheet everytime no matter what page i save on. I need to know the code and how to make it run on opening the spreadsheet.



Insert A Spreadsheet From Other Workbook
How can I insert a spreadsheet from other workbook using VBA? Depending on parameters I would set a code to insert a certain spreadsheet from an external workbook. I just couldn't find the "insert" procedure.

Insert File Names Into Spreadsheet
I guess I'm kind of running around in the dark. Your help would be appreciated. I'm trying to insert a list of filenames from one folder into my spreadsheet. As you might have guessed, it doesn't work. Any suggestions?

Sub money()
' money Macro

Dim fso, objFolder, obFileList, folderpath, fullpath, xl, i, j

folderpath = Worksheets("Money Chart").Range("A2")

Set fso = CreateObject("Scripting.FileSystemObject")

Set objFolder = fso.GetFolder(folderpath)

Set objFileList = objFolder.Files

Set xl = CreateObject("Excel.application")

If Not fso.folderexists(folderpath) Then

MsgBox ("Invalid File Path")

End If

xl.Application.Visible = True

Set objSheet = xl.ActiveWorkbook.Worksheets("Money Chart").Name

i = 4

j = 1

For Each file In objFileList

fullpath = folderpath & "" & file.Name

If fso.getextensionname(fullpath) = "txt" Then

objSheet.Cells(i, j).Value = file.Name

i = i + 1

End If


xl.DisplayAlerts = False

objSheet.SaveAs ("C:FormsTest.xls")


End Sub

Excel Spreadsheet From FTP To Customized Excel Spreadsheet
Hi guys!!

Help on this PLEASE!!

I get an EXCEL SPREADSHEET via FTP. I want to take that xls file and convert it to my own format which is ALSO an xls file. How can I do that? I went through your forums but cannot find what I am looking for. Basicly want to push a button and it must take the "rough" xls and create an new xls with the data "neat" so that I can use it.

For example the original xls has nonsense at the bottom and top like a address and names that I do not use, ONLY the "Item Codes" and "Item Description". Luckily the "Item Codes" and "Item Description" is in one column.

Stoping A Macro Running In A Excell Spreadsheet
Im opening a excell object via VB BUT the spreadsheet that im opening contains macros how can i diable this from within vb or at least stop them... below is the code im using

VB Code:
Dim credits(4, 1) As String    n = 7    xlsfilename = "U:chrisroberts" 'the name of your closed excel book here        Set xlApp = New Excel.Application 'load a new instance of excel    xlApp.Visible = True 'or false depending if you want to view the other excel app    xlApp.DisplayAlerts = False            xlApp.Workbooks.Open xlsfilename         curcell = xlApp.ActiveCell(n, 2)    credits(1, 1) = curcell    credits(2, 1) = "x"    credits(3, 1) = xlApp.ActiveCell(n, 14)    credits(4, 1) = xlApp.ActiveCell(n, 9)    MsgBox ("N = " & n)    MsgBox ("Action ID :" & credits(1, 1))    MsgBox ("Pending Status :" & credits(2, 1))    MsgBox ("Credit Amount :" & credits(3, 1))    MsgBox ("HDM :" & credits(4, 1))         xlApp.Quit    Set xlApp = Nothing

Image Or Picture Box Picture Resize
When ever you load a picture into a picture box with the stretch property to true, it will of course expand to the size of the image. Lets say I have an image 500x300pixels. I want it to fit into my image or picture box that is 250x150. Kind of like how thumb nails work. Or on windows explorer when you single click a file, it will show a smalled size of the actual image. There might be a property for this, ive just been looking at VB for so long working on a project that if its there, I dont see it. Thanks.

I Need Macro To Resize Too Wide Graphics In Word 2000
My question is this. I write user manuals that start out as .rtf files that I export from ForeHelp, a Windows help authoring tool. I have tons of screen shots in this doc, many of which are wider than 6.5 inches. This means they don't fit within the margins when it comes into Word. Is there some way I can make the graphics fit inside the margin when I open it? Or perhaps a search macro that selects the oversized graphic would help?

I tried to write a macro that would search for a graphic (^g in the search and replace thingy) but that lands on graphic bullets too that don't need to be resized. Some of the graphics that are too wide should not be replaced automatically (because the height gets screwed up and isn't proportional anymore), but should be fixed be a different method, so I would want to mark these with a style code or something I can search for later. Currently, I have to page down through hundreds of pages (up to 800) to find the graphics that need to be resized. Ugh! Then I click on a custom macro on my toolbar that resizes it. This macro works fine, but I have to find and then select the graphic before it works.

Is there some way I can search for only graphics that are wider than 6.5 inches and perhaps taller than a certain height? I don't know how to write custom macros but I can use the recorder just fine. How would I record something like that? I do know how to get into the VB Macro editor and insert While/Wend statements to get it to repeat till the end, but that's all the coding I know.
Betty Gravlin, Software Technical Writer

Converting An Excel 2002 Macro To An Excel 95 Macro
Hi there, Iíve finally got my macro program to work (thanks everyone). Now I have to load the macro on a much older machine. I wrote the Macro on Excel 2002 and now Iím trying to run it on Excel for Windows 95 Version 7.0. Iíve loaded it up, but there are all sorts of errors. Does anyone know of a simple way to convert the macro code so it will run smoothly on Excel 7.0?

Invalid Data In Excel Spreadsheet/count Group Of Items In Excel Sprdsh
Please help:
I populated an excel spreasheet with data from access table, using CopyFromRecordset function.  The process was successful and all the fields displayed correctly in the spreadsheet, except the date field which displayed:"########".  What did I do wrong?

What vb code can I used to count group of items in the spreadsheet.
Any insight will be very helpful.

Picture Resize
is there any way in VB6, to resize a photo from 600x800 pixels to fit in a picturebox or imagebox, in a size smaller the the original photo, say 200x300 pixels

Picture Resize
Hello, is there a way to resize an image before storing it in a database?

I have an image control in a form (VB6) and i'm storing the selected image (using ADODB.Stream) in a MsSQL2k database. But instead of going to another application like Photo Editor to resize de picture, is it possible to do it directly from VB before storing it?



Picture Resize
is it possible to resize just some locations of a picture in a picture box ? i can't split the picture..

I started a similar thread some time ago, and someone gave me a code to stretch/shrink a BMP-file in a picturebox.
But I would really like to do this with a JPG and gif aswell (in fact any imagefile VB understands)
I cannot use the ImageBox-control because i need to draw on the picture

So if somebody could help me out with this it would be appreciated. Thank you in advance.

Resize Picture
I am trying to resize picture but it is showing error "invalid picture". this is the code

vb Code:
Private Sub Timer1_Timer()Dim ret As Longi = i + 1ret = GetDC(GetDesktopWindow)BitBlt Picture1.hDC, 0, 0, Screen.Width / 15, Screen.Height / 15, ret, _0, 0, SRCCOPYPicture1.PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeightSavePicture Picture1.Image, "C:screenshots" & "image" & i & ".jpg"End Sub

Picture Resize
I have to do a program where in a form I chose a photo and in another form I can see the photo after a resize.
but when it runs the photo is resized but picture box remain small.
what can i do?

For Resize According To Picture Box
ok i need to resize a form accoding to the size of the picture box,

i've set both scalemodes to pixel and i use this code... but it doesnt work

VB Code:
frmmain.width = frmmain.picture.scalewidthfrmmain.height = frmmain.picturescaleheight

any help?

Resize Picture?
How can i resize a bmp to 800 x 600 pixels?

Ive searched this forum for answers but cant seem find any examples that do what i want

Any help would be greatly appriciated.

Picture Resize???
I wanna know if its possible to make a form picture strech out to the size of the form. Like if I make my castles property to maximise i don't want it to have just a little picture i want it to strech with the form.

Resize Picture Box
how can i scale a picture box. im creating a screen grab program, and i get the screen shot great, but how can i set it so that when the picture box is reduced (say to 1/4 the screen size) that instead of just showing the top left quarter, it shows the whole screen, but 1/4 the size?


Resize Picture
Can I resize picture as the size of Picture Box that I have on form. I want to show whole picture in picture box.

Thanks in advance

Picture Box Resize
How can I display a picture in a picture or an image box and make the picture the largest size it can be in the box without changing its Height:width ratio?


How To Resize Picture In Vb

i want to know how to resize a picture file in Vb....
if i have a picture file in my disk and i want to resize it and to do it more less size.... can i do that in VB?

Copyright © 2005-08, All rights reserved