Hi Udhay
Pre-condition for this Macro is: Excel 1.xls exists in C:\temp folder.
This Macros does the following:
1. opens an excel sheet at Location: C:\temp\1.xls, from existing Macro
Handle
2. Then adds a New Code module: Module1, to this .xls file
3. Adds definition of a Function Named: NewFunction, to the Module1.
4. Saves the changes to the 1.xls file and saves it.
Now after Macro execution you can check the changes are made to the 1.xls
file are made by pressing ALT+F11 in 1.xlsm file.
On Thursday, August 7, 2014 1:23:27 PM UTC+5:30, udhaya kumar wrote:
>
> Hi All,
>
> While running the below code for excel macro i go the error " Programmatic
> access to VB project is not trusted"
>
> Set XLHandle = CreateObject("Excel.Application")
> XLHandle.DisplayAlerts = False
> Set XLBook = XLHandle.WorkBooks.Open("c:\temp\1.xls")
> Set objCodeModule = XLBook.VBProject.VBComponents.Item("Module1")
> .CodeModule
> sNewCode = "Public Function NewFunction(ByVal intStartRow, ByVal
> intEndRow)" & vbCrLf
> sNewCode = sNewCode &" Sheet1.Range(Sheet1.Cells(intStartRow, 1),
> Sheet1.Cells(intEndRow, 10)).Select" & vbCrLf
> sNewCode = sNewCode &" Selection.Interior.ColorIndex = 35" & vbCrLf
> sNewCode = sNewCode &"End Function" & vbCrLf
> objCodeModule.AddFromString(sNewCode)
> XLBook.Save
> XLBook.Close
> XLHandle.Quit
> Set objCodeModule = Nothing
> Set XLBook = Nothing
> Set XLHandle = Nothing
>
> Please give workaround for this error
>
>
> Regards,
> Udhay
>
--
--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en
---
You received this message because you are subscribed to the Google Groups "QTP
- HP Quick Test Professional - Automated Software Testing" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.