I have used the below code in solidworks macro to override the dimension and its working fine, when I used same code in excel vba I am getting errors. Anyone please help me on this.
Code which I used,
Dim swApp as SldWorks.SldWorks
Dim Part as ModelDoc2
Dim SelMgr as SelectionMgr
Dim DispDim as DisplayDimension
Dim theVal as Double
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
boolstatus = Part.Extension.SelectByID2("D1@Sketch1@Part1@DV2","DIMENSION",0,0,0, FALSE,0, Nothing,0)
Set DispDim = SelMgr.GetSelectedObject6(1,0)
theVal = (50 * 25.4) / 1000
DispDim.SetOverride True, theVal
End Sub
API
Macro

You have to use GetObject or CreateObject to get the swApp variable. Application.Sldworks only works from a SolidWorks macro. "Application" means "The thing running the code". Since Excel is running the code, SldWorks is not a thing you can get from the Excel application object. You also have to go to Tools->References in the VBA editor and add references to the SolidWorks libraries.
Thank you Josh. I have updated the code based on your suggestion, but I am not sure about the selection manager and also not familiar with vba. So can you please help me on this?
Dim swApp as Object
Dim Part as Object
Dim boolstatus as Boolen
Dim SelMgr as SelectionMgr
Dim DispDim as DisplayDimension
Dim theVal as Double
Sub main()
Set swApp = CreateObject("Sldworks.Application")
Set Part = swApp.NewDocument("C:\Solidworks2015\templates",0,0,0)
Set SelMgr = Part.SelectionManager
boolstatus = Part.Extension.SelectByID2("D1@Sketch1@Part1@Drawing View2","DIMENSION",0,0,0, FALSE,0, Nothing,0)
Set DispDim = SelMgr.GetSelectedObject6(1,0)
theVal = (50 * 25.4) / 1000
DispDim.SetOverride True, theVal
End Sub
No, sorry. There are loads of tutorials and training materials on VBA readily available on the internet. I am far to lazy to write you a custom one here.