VBA code causes excel to crash when saved and/or (file has external links)

jonfen100

New Member
Joined
Aug 4, 2016
Messages
1
Hey guys!

Thank you for the immense help you have already given by being so active.

I have an excel file with some VBA code (fairly new to the (for me) more advanced stuff).

The code is working fine, and was working when I was creating it. Now when I make a change in the file, save, close, reopen, and enable content it crashes. If I don't enable content and try to open the VBA Editor it crashes.

The file has external connections to a website, and I'm using ActiveX controls. I have tried disabling connections, saving in different formats, compiled the code.

I have determined that the error is cause by the next block of code.

Code:
Private Sub Worksheet_Calculate()
Static oldval
If Range("E9").Value <> oldval Then
    oldval = Range("E9").Value


If Range("E9").Value <> PrevVal Then


If Sheets("Mail Template").Range("E9").Value = "UK" Then


Sheets("Main Texts").Range("A6:B36").Copy


Sheets("Mail Template").Range("A7").PasteSpecial
Range("A33:B35").ClearContents
PrevVal = Range("E9").Value


Range("B2").Select
    Range("B2").ClearContents
    SendKeys "{F2}"
    SendKeys "{NumLock}"


End If


If Sheets("Mail Template").Range("E9").Value = "DK" Then


Sheets("Main Texts").Range("D6:E36").Copy


Sheets("Mail Template").Activate


Range("A7").PasteSpecial
PrevVal = Range("E9").Value


Range("B2").Select
    Range("B2").ClearContents
    SendKeys "{F2}"
    SendKeys "{NumLock}"
End If
If Sheets("Mail Template").Range("E9").Value = "SE" Then


Sheets("Main Texts").Range("G6:H36").Copy


Sheets("Mail Template").Range("A7").PasteSpecial
PrevVal = Range("E9").Value


Range("B2").Select
    Range("B2").ClearContents
    SendKeys "{F2}"
    SendKeys "{NumLock}"
End If
If Sheets("Mail Template").Range("E9").Value = "US" Then


Sheets("Main Texts").Range("M6:N30").Copy


Sheets("Mail Template").Range("A7").PasteSpecial
Range("A32:B35").ClearContents


Range("B2").Select
    Range("B2").ClearContents
    SendKeys "{F2}"
    SendKeys "{NumLock}"
End If
If Sheets("Mail Template").Range("E9").Value = "EU" Then


Sheets("Main Texts").Range("K6:L30").Copy


Sheets("Mail Template").Range("A7").PasteSpecial
Range("A32:B35").ClearContents
PrevVal = Range("E9").Value


Range("B2").Select
    Range("B2").ClearContents
    SendKeys "{F2}"
    SendKeys "{NumLock}"
End If
If Sheets("Mail Template").Range("E9").Value = "NO" Then


Sheets("Main Texts").Range("I6:J36").Copy


Sheets("Mail Template").Activate


Range("A7").PasteSpecial
PrevVal = Range("E9").Value


Range("B2").Select
    Range("B2").ClearContents
    SendKeys "{F2}"
    SendKeys "{NumLock}"
End If
End If
End If
End Sub

Hope someone can help. I have a feeling the problem is with the first few lines of code.
Now I'll og and try to help others with other Excel problems in this forum

/jonfen100
 

Forum statistics

Threads
1,226,824
Messages
6,193,164
Members
453,778
Latest member
RDJones45

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