Hi
I am getting error on this line - Object variable or with block variable not set
Dim cropRect As RectangularGradient
Dim originalHeight As Long
Dim cropHeight As Long
originalHeight = img.Height
cropHeight = originalHeight * 0.3 ' 30% of the original height
' Set the cropping rectangle (center at the bottom)
Dim cropRect As RectangularGradient
cropRect.Left = 0
cropRect.Right = img.Width
Daniel WrightPosted Mar 20, 2025, 3:10 PM
It seems like the error "Object variable or with block variable not set" occurs in your code snippet because you are declaring the `cropRect` variable as a `RectangularGradient` type but not initializing it before trying to access its properties like `Left` and `Right`.
To resolve this error, you need to instantiate the `RectangularGradient` object before setting its properties. Here is an example of how you can create an instance of `RectangularGradient` and set its properties:
By using the `New` keyword, you create a new instance of the `RectangularGradient` class, allowing you to access its properties without triggering the "Object variable or with block variable not set" error.
Make sure to adjust this code within your existing subroutine or function to properly initialize the `cropRect` object before attempting to access its properties. This adjustment should help you overcome the error you were experiencing. If you encounter any further issues or have additional questions, feel free to ask!