LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Protecting macro code programatically

Hi all,

We are using Excel for reporting in our organization.
Basically there is a Java web application which instantiates Excel 2007 with
an XLAM. This XLAM opens a Report Template(an .xls, .xlsm file, name
supplied as
command line parameter). The Template has a data sheet where we have multiple
ranges and the Report sheet which shows the final report based on the data
from the DataSheet. The ReportSheet contains formulas to show the final
output. It could contain Charts/Graphs also. The data is fetched from SQL
server and is pasted on the Ranges. And finally when all the data is pasted
and Macro is run the Template is saved as a Final Report somewhere on the
Report Server.

The Excel runs in the background in all this process. There could be
multiple instances of Excel running on the same box. The instances run under
separate WindowStation.

In this process depending on the options selected by the end user, the Report
options are applied on the final report workbook. The some of the Report
options are Protect Workbook, Protect Worksheets, Protect Macro Code,
Delete Macro code, etc.

I am facing a problem when it comes to Protecting Macro Code.
I believe that there is no API/Excel Object Mode available to accomplish
this task.

Given below is the code I am using for protecting the macro code.

Sub protectMacroCode()

With Application
.CutCopyMode = False
.DisplayAlerts = False

.SendKeys "%{F11}", True
.SendKeys "%T", True
.SendKeys "E", True
.SendKeys "^{TAB}", True
.SendKeys "%V", True
.SendKeys "{TAB}" & Trim("XXXXXX"), True
.SendKeys "{TAB}" & Trim("XXXXXX"), True
.SendKeys "~", True
.SendKeys "%{F11}", True
End With
End Sub

The XLAM writes the above code to the Report Workbook and Excutes this
macro code. The macro is successfully written in the workbook but does
not work as expected when call from XLAM.

Whereas this particular piece of code works fine when the workbook has
this macro already present and the XLAM just executes it.

If anybody have any idea please let me know as it is a blocking issue in our
process.

Any help appreciated.

Thanks in advance.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
programatically deleted code still triggers macro warning Ken Excel Programming 4 October 22nd 07 11:41 PM
protecting macro code julian_m Excel Programming 2 January 26th 06 02:23 AM
Deleting macro code programatically Terry Lowe[_3_] Excel Programming 1 September 1st 04 02:30 AM
Hiding/Protecting the code of macro Mario[_6_] Excel Programming 6 January 15th 04 09:06 PM
protecting macro code John Wilson Excel Programming 0 July 23rd 03 04:06 PM


All times are GMT +1. The time now is 09:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"