Lock Cell After Data Import from an External Program via DDE

CRLCHS

New Member
Joined
Aug 16, 2017
Messages
2
I have data acquisition software (DASYLab) that is gathering certain data for me. I have the data programmed to dump in to an excel file from the acquisition software. Once in the excel file, it is not allowed to be edited in any way. The problem I am running across is that when running my VBA that locks the selected group of cells where the data dumps, it isnt triggered. It only triggers once the actual cell is physically selected and any info is put in the cell. Once clicked out of, the cell that was just edited is locked. I cannot figure out how to trigger the cells to lock upon data dump.


The data is automatically imported via DDE from the data acquisition software to a saved workbook template. After batch production is complete and it is the end of the day, and the technician selects "stop recording" in the software, and it is programmed to automatically "save as" the template with the date/time. After the "save as" copy is stored, the template is closed without saving changes to the template, thus returning it back to a blank template.

Please Help! My Code is

[MENTION]
1 Private Sub Worksheet_Change(ByVal Target As Range)
2 Dim xRg As Range
3 On Error Resume Next
4 Set xRg = Intersect(Range("A1:E300"), Target)
5 If xRg Is Nothing Then Exit Sub
6 Target.Worksheet.Unprotect Password:="123"
7 xRg.Locked = True
8 Target.Worksheet.Protect Password:="123"
9 End Sub[/MENTION]
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Well pasting my code the way i thought i was suppose to clearly didn't work. Let me try again. Also - if it isn't clear, i have zero experience in any of this so your patience is appreciated

Code:
[/COLOR][COLOR=#333333]1 Private Sub Worksheet_Change(ByVal Target As Range)[/COLOR]
[COLOR=#333333]2 Dim xRg As Range[/COLOR]
[COLOR=#333333]3 On Error Resume Next[/COLOR]
[COLOR=#333333]4 Set xRg = Intersect(Range("A1:E300"), Target)[/COLOR]
[COLOR=#333333]5 If xRg Is Nothing Then Exit Sub[/COLOR]
[COLOR=#333333]6 Target.Worksheet.Unprotect Password:="123"[/COLOR]
[COLOR=#333333]7 xRg.Locked = True[/COLOR]
[COLOR=#333333]8 Target.Worksheet.Protect Password:="123"[/COLOR]
[COLOR=#333333]9 End Sub[/COLOR][COLOR=#333333]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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