Help me fix the SIZE of my OBJECT!

tgrunwald

New Member
Joined
Sep 17, 2007
Messages
41
I am loading a PDF file into a worksheet. The PDF file is supposed to fit into a rounded rectangle shape when loaded.

When the workbook first is opened and the sub is run, it doubles the width of the PDF. But sometimes after trying just one time it fits into the rectangle. Other times I have to delete the PDF and rerun the sub multiple times before it loads correctly. Does anyone have any ideas?

Here is the code:
/code
Option Explicit
Sub LoadIncomingInvoice()

Dim myPDFobj As OLEObject
Dim strFile As String


Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Sheet1.Unprotect Password:="FIGHT4LOVE"

On Error Resume Next
' Get the path of the PDF
strFile = Application.GetOpenFilename(FileFilter:= _
"Adobe Acrobat Files (*.pdf), *.pdf", Title:= _
"Please select a file")
' Store the path so we can print it later
Sheet1.Range("I100").Value = strFile
'Set the object
Set myPDFobj = ActiveSheet.OLEObjects.Add(Filename:= _
strFile, Link:=True, DisplayAsIcon:=False)
'Set the object properties, try and fit them into the space occupied by
''Rounded Rectangle 48' . This is where something bugs out. Whenever
'I start the program and call this sub, the PDF loads the first time twice as
'it should. But on subsequent loads, it fits just fine.
With myPDFobj
.Top = ActiveSheet.Shapes("Rounded Rectangle 46").Top
.Left = ActiveSheet.Shapes("Rounded Rectangle 46").Left
.Width = ActiveSheet.Shapes("Rounded Rectangle 46").Width
.Height = ActiveSheet.Shapes("Rounded Rectangle 46").Height
.ShapeRange.ScaleWidth 0.96, msoFalse, msoScaleFromTopLeft 'Problem?
.ShapeRange.ScaleHeight 1.05, msoFalse, msoScaleFromTopLeft 'Problem?
.Name = "IncomingInvoice"
End With

On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
'Load the logfile
Sheet1.Range("L29").Value = Now & ": "
Sheet1.Range("N29").Value = "Incoming Invoice loaded into the system by " & WindowsUser
Sheet1.Protect Password:="FIGHT4LOVE"
strFile = vbNullString
End Sub
/code
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I am loading a PDF file into a worksheet. The PDF file is supposed to fit into a rounded rectangle shape when loaded.

When the workbook first is opened and the sub is run, it doubles the width of the PDF. But sometimes after trying just one time it fits into the rectangle. Other times I have to delete the PDF and rerun the sub multiple times before it loads correctly. Does anyone have any ideas?

Here is the code:
/code
Option Explicit
Sub LoadIncomingInvoice()

Dim myPDFobj As OLEObject
Dim strFile As String


Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Sheet1.Unprotect Password:="FIGHT4LOVE"

On Error Resume Next
' Get the path of the PDF
strFile = Application.GetOpenFilename(FileFilter:= _
"Adobe Acrobat Files (*.pdf), *.pdf", Title:= _
"Please select a file")
' Store the path so we can print it later
Sheet1.Range("I100").Value = strFile
'Set the object
Set myPDFobj = ActiveSheet.OLEObjects.Add(Filename:= _
strFile, Link:=True, DisplayAsIcon:=False)
'Set the object properties, try and fit them into the space occupied by
''Rounded Rectangle 48' . This is where something bugs out. Whenever
'I start the program and call this sub, the PDF loads the first time twice as
'it should. But on subsequent loads, it fits just fine.
With myPDFobj
.Top = ActiveSheet.Shapes("Rounded Rectangle 46").Top
.Left = ActiveSheet.Shapes("Rounded Rectangle 46").Left
.Width = ActiveSheet.Shapes("Rounded Rectangle 46").Width
.Height = ActiveSheet.Shapes("Rounded Rectangle 46").Height
.ShapeRange.ScaleWidth 0.96, msoFalse, msoScaleFromTopLeft 'Problem?
.ShapeRange.ScaleHeight 1.05, msoFalse, msoScaleFromTopLeft 'Problem?
.Name = "IncomingInvoice"
End With

On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
'Load the logfile
Sheet1.Range("L29").Value = Now & ": "
Sheet1.Range("N29").Value = "Incoming Invoice loaded into the system by " & WindowsUser
Sheet1.Protect Password:="FIGHT4LOVE"
strFile = vbNullString
End Sub
/code


purhaps try doing the below and see what happens
'With
myPDFobj
.Top = ActiveSheet.Shapes("Rounded Rectangle 46").Top _
.Left = ActiveSheet.Shapes("Rounded Rectangle 46").Left _
.Width = ActiveSheet.Shapes("Rounded Rectangle 46").Width _
.Height = ActiveSheet.Shapes("Rounded Rectangle 46").Height _
.ShapeRange.ScaleWidth 0.96, msoFalse, msoScaleFromTopLeft 'Problem? _
.ShapeRange.ScaleHeight 1.05, msoFalse, msoScaleFromTopLeft 'Problem?_
.Name = "IncomingInvoice"
'End With
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top