Resizing A Picture In Excel Using Vba |
Resizing A Picture In Excel Using Vba - Excel |
|
As the title goes this is as simple as it gets. The macro worked good when I was using excel 2003 but now that I have 2007 everything works for except the resizing (Picture.Width & Picture. Height).
Code:
Sub AddImage() Dim strPath As String Dim strFile As String Dim Picture As Object Dim Response As String Dim C As Range strPath = "C:\\Photos\" For Each C In Range("A1", Range("A65536").End(xlUp)) If C 0 Then With C.Offset(0, 1) Set Picture = Nothing On Error Resume Next Set Picture = Sheets("Raw Pix").Pictures.Insert(strPath & C.Value & ".jpg") Picture.Top = .Top Picture.Left = .Left Picture.LockAspectRatio = msoTrue Picture.Width = 157 Picture.Height = 138 End With End If NextC: Next C End Sub
I have tried to record some macros while I am resizing the pictures but to no avail the macros are blank.
Please help
Thanks!
Similar Topics
I want to be able to reference it from a cell so that depending on a
validation list a different picture is shown.
Is this possible in Microsoft Exec 2000
Thanks!
A specific problem is cells which don't have borders show up with very light grey borders in Outlook. This, I do not want.
TiA
I have several accumulated values from other spreadsheets on my spreadsheet and I'm combining and organizing them on mine. However, the cell alignment isn't working properly as you can see in the picture below.
Now, I can certainly retype these values and align them and they'll align all nice and neat; however, I have a huge Column and retyping that column would take an inordinate amount of time.
I searched earlier on cell alignment and couldn't find anything. Any help is appreciated.
Sincerely,
Bill
We will be building 8 "widgets" a day.
We will work 10 hours a day.
There is a 20 minute break at 9:20 am.
Production shuts down for lunch 30 minutes for lunch at 12:30.
Production starts at 6:00 am.
Here is what I can do.
Production cycle time = (10*60)-30/8 or 71.25 minutes
If we start at 6:00 am, the first scheduled cycle completion time = TIME(6,0,0+71.25/1440)
My problem is when I am trying to use a logical "IF' statement to account for the 20 minute break or lunch and still calculate the end of each cycle time through the day I receive a number of error messages.
This is the formula I am trying to make work. I have the cell the formula is in, formatted with a "mm,ss" format.
=(IF(D4+G1/1440>9:20,(D4+G1)/24,(D4+G1+15)/1440))
I have included an attachment to help (a picture is worth a thousand words).
Any help will be greatly appreciated.
I have bought a number of books in an attempt to figure this out, and I am still stumped
Sub OpenPDF() 'Dim pdf As String On Error Resume Next 'pdf file to open pdf = "K:\PDF\mypdf.pdf" 'open the pdf file ActiveWorkbook.FollowHyperlink pdf End Sub
So then I tried to create an instance of acrobat by setting a reference to the acrobat object but I can't get this to work either!
The code I'm using is Code:
Sub OpenPDF() Dim pdf As AcroPDDoc Dim strPDF As String Set pdf = CreateObject("AcroExch.PDDoc") 'pdf file to open strPDF = "K:\PDF\mypdf.pdf" 'open the pdf file pdf.Open strPDF End Sub
Any ideas what could be wrong with either approach?
Thank-you
Code:
Sub Mail() Dim OutApp As Object Dim OutMail As Object Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = "cbelcher@jpfryelaw.com" .CC = "" .BCC = "" .Subject = "Burden Report" .Body = ActiveSheet.Range("A1:D12") .Attachments.Add ("C:\Documents and Settings\cbelcher\Desktop\Burden Report.xls") End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing Set objMsg = Nothing End Sub
For 19,999 it show
Ringgit Malaysia : Nineteen Thousand Nine Hundred NinetyNine Only
For 20,000 and above it show
Ringgit Malaysia : Thousand Only
Code as below:
Function SpellNumber(amt As Variant) As Variant
Dim FIGURE As Variant
Dim LENFIG As Integer
Dim i As Integer
Dim WORDs(19) As String
Dim tens(9) As String
WORDs(1) = "One"
WORDs(2) = "Two"
WORDs(3) = "Three"
WORDs(4) = "Four"
WORDs(5) = "Five"
WORDs(6) = "Six"
WORDs(7) = "Seven"
WORDs(8) = "Eight"
WORDs(9) = "Nine"
WORDs(10) = "Ten"
WORDs(11) = "Eleven"
WORDs(12) = "Twelve"
WORDs(13) = "Thirteen"
WORDs(14) = "Fourteen"
WORDs(15) = "Fifteen"
WORDs(16) = "Sixteen"
WORDs(17) = "Seventeen"
WORDs(18) = "Eighteen"
WORDs(19) = "Nineteen"
tens(2) = "Twenty"
tens(3) = "Thirty"
tens(4) = "Fourty"
tens(5) = "Fifty"
tens(6) = "Sixty"
tens(7) = "Seventy"
tens(8) = "Eighty"
tens(9) = "Ninety"
FIGURE = amt
FIGURE = Format(FIGURE, "FIXED")
FIGLEN = Len(FIGURE)
If FIGLEN < 12 Then
FIGURE = Space(12 - FIGLEN) & FIGURE
End If
If Val(Left(FIGURE, 9)) > 1 Then
SpellNumber = "Ringgit Malaysia : "
ElseIf Val(Left(FIGURE, 9)) = 1 Then
SpellNumber = "Ringgit Malaysia "
End If
For i = 1 To 3
If Val(Left(FIGURE, 2)) < 20 And Val(Left(FIGURE, 2)) > 0 Then
SpellNumber = SpellNumber & WORDs(Val(Left(FIGURE, 2)))
ElseIf Val(Left(FIGURE, 2)) > 19 Then
Ntow = Ntow & tens(Val(Left(FIGURE, 1)))
SpellNumber = SpellNumber & WORDs(Val(Right(Left(FIGURE, 2), 1)))
End If
If i = 1 And Val(Left(FIGURE, 2)) > 0 Then
SpellNumber = SpellNumber & " Crore "
ElseIf i = 2 And Val(Left(FIGURE, 2)) > 0 Then
SpellNumber = SpellNumber & " Hundred "
ElseIf i = 3 And Val(Left(FIGURE, 2)) > 0 Then
SpellNumber = SpellNumber & " Thousand "
End If
FIGURE = Mid(FIGURE, 3)
Next i
If Val(Left(FIGURE, 1)) > 0 Then
SpellNumber = SpellNumber & WORDs(Val(Left(FIGURE, 1))) + " Hundred "
End If
FIGURE = Mid(FIGURE, 2)
If Val(Left(FIGURE, 2)) < 20 And Val(Left(FIGURE, 2)) > 0 Then
SpellNumber = SpellNumber & WORDs(Val(Left(FIGURE, 2)))
ElseIf Val(Left(FIGURE, 2)) > 19 Then
SpellNumber = SpellNumber & tens(Val(Left(FIGURE, 1)))
SpellNumber = SpellNumber & WORDs(Val(Right(Left(FIGURE, 2), 1)))
End If
FIGURE = Mid(FIGURE, 4)
If Val(FIGURE) > 0 Then
SpellNumber = SpellNumber & " And Cents "
If Val(Left(FIGURE, 2)) < 20 And Val(Left(FIGURE, 2)) > 0 Then
SpellNumber = SpellNumber & WORDs(Val(Left(FIGURE, 2)))
ElseIf Val(Left(FIGURE, 2)) > 19 Then
SpellNumber = SpellNumber & tens(Val(Left(FIGURE, 1)))
SpellNumber = SpellNumber & WORDs(Val(Right(Left(FIGURE, 2), 1)))
End If
End If
FIGURE = amt
FIGURE = Format(FIGURE, "FIXED")
If Val(FIGURE) > 0 Then
SpellNumber = SpellNumber & " Only "
End If
End Function
Alanda
I'm hoping someone can help me.
I need to be able to clear the contents of cells in column C, D, E, H if the value of column Q equals HELLO for arguments sake.
Clearing the contents of an entire row is not a problem, however when it comes to resizing rows I seem to come unstuck.
Related thread: http://www.mrexcel.com/forum/showthread.php?t=476993
Any help would be appreciated.
First post on the forum, have only recently joined and im hoping that someone can help me before my head explodes!
I am trying to prepare a simple Material Quantity List for some Steel materials.
The materials are all in specific sizes.
What i want to do is, as i input the length, width and height of the structure in the spreadsheet, the Material Quantity List will generate the quantity of each piece of material i will need.
Does anybody know of a formula for this. I have been trying to use the IF function and getting absolutely nowhere, all suggestions will be highly appreciated!!
The question:
How can you prevent a cell's contents from overflowing into the next cell?
Of course, you can make the column wider or turn on text wrapping, but you might not want to. Each of those solutions can mess up the layout of your sheet. You may just want to truncate the value.
Some people have suggested putting a space in the next cell. This is unnecessary, a pain in the but, and will mess up any ISBLANK type formulas, among other things.
The solution:
Select the cells in question and turn on text wrapping (Format>Cells>Alignment>Wrap Text).
Now select the row(s) in question and manually set the row height, by right clicking the row number and selecting "Row Height". Check the height of an adjacent row for a good value.
Your cells will now not spill over either horizontally or vertically. They will simply truncate anything that doesn't fit.
Be careful now, because parts of your data may be hidden. This can cause its own set of problems if one or two digits are neatly hidden away. Think ahead if other people might be using this sheet, and not be expecting to have some data hidden.
Tested in Excel 2002
I have the following code to put data from a VBA userform into Excel
Dim Sh As Worksheet
Dim Rng As Range
Set Sh = ActiveSheet
Set Rng = Sh.Range("A65536").End(xlUp).Offset(1, 0)
With Rng
.Cells(1, 1) = Surname.Text
.Cells(1, 2) = forename.Text
.Cells(1, 3) = datein.Text
.Cells(1, 4) = origin.Text
.Cells(1, 5) = Addressee.Value
.Cells(1, 6) = usual.Value
.Cells(1, 7) = dateto.Text
.Cells(1, 8) = permission.Value
.Cells(1, 9) = dateseen.Text
.Cells(1, 10) = requestview.Value
.Cells(1, 11) = Invoice.Value
.Cells(1, 12) = notes.Text
.Cells(1, 13) = datecompleted.Text
.Cells(1, 14) = holdsend.Value
.Cells(1, 15) = fee.Text
.Cells(1, 16) = notes2.Text
.Cells(1, 17) = dateseen.Text
.Cells(1, 18) = invoicesent.Text
.Cells(1, 19) = Paid.Text
.Cells(1, 20) = Complete.Value
End With
What I want to do next is click on the surname on the speadsheet and call up the userform with the fields complete for that person. I would also like to be able to edit/update the form and update the information on the speadsheet accordingly.
Any help would be greatly appreciated!
Many thanks!
I keep getting errors, saying I'm not formulating my if statements correctly.
This is what I have:
Code:
Private Sub Workbook_Open() If Range("a1") = "" Then macrox else do nothing End If End Sub
I have a spreadsheet with some cells setup with a drop-down list containing
Y, N or N/A
This is being used on a TabletPC but if I make a mistake or need to change
back to a blank field I have to invoke the soft keyboard, activate the cell
and hit backspace then close the soft keyboard - quite a long-winded
procedure just to change an incorrect choice!
What I would like to do is add a blank to the list so if I have to revert
back to a blank I can just use the stylus to choose a blank from the chooser
list.
How do I add the option of inputting a blank from the Data Validation List
bearing in mind I am using the Data Validation Source box for entering my
choices directly and not specifying a range of cells?
I have tried adding "" and even a space to no avail.
Although not a betting man I would wager there is a simple 'fix' for this
but things are only simple if you know how in the first instance! ;^)
--
Thanks & regards,
-pp-
I have set up a workbook that is sent out to lots of different users. They each keep and use their own copy.
I have set it up so that everything looks OK and is visible on MY screen, but I'm conscious that some users may have different screen sizes, different toolbars set up, and so on, which might make some parts not immediately visible to them.
I have set up an auto-execute macro which automatically sets the zoom factor to best fit, for several of the worksheets, and this works fine.
Here's the code that does it.
Code:
Sheets("WELCOME").Select Range("A1:N18").Select ActiveWindow.Zoom = True
By repeating this code for each worksheet, I can make each one be zoomed just right.
However, the file contains 8 sheets that are all identically laid out, except the number of rows is different.
What I want to do is go to the worksheet that has the largest number of rows (it's always the same worksheet, so I know which one it is), set the zoom factor for THAT worksheet (which I can do, and it always has the same number of rows), and then take THAT zoom factor, whatever it is - and it will vary depending on the user - and apply that to the other worksheets that have a similar layout.
I could just go through each worksheet and zoom it automatically, but that would mean that some of the sheets looked very large, others very small, and I'd like them to have a consistent appearance.
I could also specify a range on each worksheet that was similar to the appropriate range on the longest worksheet, and zoom that automatically, but that's not ideal either, because some of the row heights vary from sheet to sheet, and again I'll end up with different font sizes.
Anyone know how to do this ?
I am using below code to Select the Visible rows in the target range:
Code:
Range("A:p").SpecialCells(xlCellTypeVisible).Select
Problems in this code a
1) after applying the filter, while selecting the data it is selecting all the rows in given range till last row on the workbook. I need this to select the the data only till the last used row in the given range.
2) It is not possible to provide the address of the first row after we apply the filter since the first row address may change depending on the values in the table.
E.g. 1st time when I am running the macro the first row in the visible filtered data is starting at Cell address A4 and next time when I will run the macro it may be A6
3) The Code is also selecting the 1st row which is a header row. How can we exclude it from selection.
Some one please revert with the solution.
Thanks in advance.
This is a very basic question, but i have been struggling for hours, so I must ask.
I I trying to simply fill a combobox on a userform from a named range on a sheet, I want to populate the combobox as soon as the userform starts. (I launch the userform from a button on the sheet) Where must I place the code? and will this code work?
Code:
Sub Button1_Click() Set UserForm1.combobox1.List = Sheets("Sheet1").Range("MyRange") UserForm1.Show End Sub
I am very new to vba, so please excuse my ignorance,
any help would be greatly appreciated
regards
jim
The code works, but it really slows my worksheet down when opening. Is there better way to write this? Thanks!
Code:
Dim myRange As Range Dim cell As Range Set myRange = Range("V6:V50000") For Each cell In myRange If cell.Value < 2 Then cell.Font.ColorIndex = 5 If cell.Value < 1 Then cell.Font.ColorIndex = 3 Next