excel VBA code not working -
i have excel sheet vba code follows
private sub worksheet_change(byval target range) if target.row = 1 , target.column = 5 dim iret integer if not isempty(range("az1").value) iret = msgbox("you have selectd size template", _ vbokonly, "select size template") exit sub end if dim arr variant arr = split(target, ",") range("r14:az14").clearcontents range("r14:az14").numberformat = "@" range("r14", cells(14, ubound(arr) + 18)) = worksheetfunction.transpose( _ worksheetfunction.transpose(arr)) range("az1").value2 = target end if end sub
i saved excel file .xlsm(macro enabled excel file) , opend in another.this code works fine in machine. not in other machine. enabled marco , allowed trust acess vba ojbect model. can figure out issue here . excel versions same in both mahcines
i want elaborate bit comment of mine correct suggestion.
first, let me repeat that- need switch on events in way
application.enableevents = true
which can run once in immediate window in vba/ide editor. know it!
second, if decided switch on events using other subroutine (or event, strange) please keep in mind there other subroutines, functions or add-ins require events switched off. long not sure why events not working should keep them not working right after macro doesn't need them more. therefore, suggestion switch events off each time close file. therefore add event thisworkbook module
:
private sub workbook_beforeclose(cancel boolean) application.enableevents = false end sub
extra tip. best option read events status @ beginning, keep information until close file. in following steps:
a) declare public variables in file
public boeventsstatus boolean
b) read status when opening file (you need figure out put line of code)
boeventsstatus = application.enableevents
c) switch on events described @ beginning
d) use beforeclose
event:
private sub workbook_beforeclose(cancel boolean) application.enableevents = boeventsstatus end sub
Comments
Post a Comment