首页 > 其他 > 详细

用AutoHotkey解决Excel中修改超链接公式会自动修改文字格式的问题

时间:2021-07-22 10:50:39      阅读:17      评论:0      收藏:0      [点我收藏+]

存在的困难

如果用了excel的超链接,一定会被Excel自动修改格式折磨过。
只要修改了公式中的任意内容,回车后单元格格式就变成蓝字,12号字体。
然后就要手动改回原来的格式,非常繁琐
技术分享图片

解决方案:

用脚本在修改前记录当前单元格的格式,设置公式后再自动设置字体格式。 记录单元格格式和恢复单元格格式的函数如下

xl := ComObjActive("Excel.application")
ac := xl.ActiveCell
objFormat := get(ac)
arrFormula := StrSplit(ac.formula, ‘"‘)
rng := inputbox("引用区域",,,ltrim(arrFormula[2],"#"))
name := inputbox("显示名称",,,ac.text)
gs := format(‘=HYPERLINK("#{1}","{2}")‘, rng,name)
xl.ScreenUpdating := false
ac.formula := gs
set(ac, objFormat)
xl.ScreenUpdating := true
return

get(cell) {
objFormat := {}
objFormat.font := {}
objFormat.interior := {}
objFormat.font.name := cell.font.name,
objFormat.font.Size := cell.font.Size,
objFormat.font.bold := cell.font.bold,
objFormat.font.italic := cell.font.italic,
objFormat.font.Strikethrough := cell.font.Strikethrough,
objFormat.font.underline := cell.font.underline,
objFormat.font.ColorIndex := cell.font.ColorIndex,
objFormat.interior.ColorIndex := cell.interior.ColorIndex,
return objFormat
}
set(cell, objFormat) {
cell.font.name := objFormat.font.name,
cell.font.Size := objFormat.font.Size,
cell.font.bold := objFormat.font.bold,
cell.font.italic := objFormat.font.italic,
cell.font.Strikethrough := objFormat.font.Strikethrough,
cell.font.underline := objFormat.font.underline,
cell.font.ColorIndex := objFormat.font.ColorIndex,
cell.interior.ColorIndex := objFormat.interior.ColorIndex,
}

用AutoHotkey解决Excel中修改超链接公式会自动修改文字格式的问题

原文:https://www.cnblogs.com/hyaray/p/15042214.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!