Solved

CREATING AN EXCEL SPREADSHEET IN VISUAL BASIC FORM

Posted on 2009-07-15
9
223 Views
Last Modified: 2013-11-26
Sorry Experts,
I'm new to the exchange and this is my first time posting. I just posted the same questions and then awarded points! So, I'm trying again.

I am attempting to create an excel spreadsheet on a vb form using a button. I believe I have the references and import statements correct. However, it throws the error "System.Security.Permissions.SecurityPermission"  when it attempts to execute the first line of code "Dim ex As New Excel.Application".

I have tried to correct it by reading other posts but am lost when it comes to assemblies and changing them.

Any help would be appreciated.

Thanks
0
Comment
Question by:reeseer74
  • 5
  • 4
9 Comments
 
LVL 1

Expert Comment

by:xemophora
ID: 24864326
What is your code thus far?  I am relatively new to this as well but actually got a start doing almost this same thing a little while back.

Are you trying to generate a form from scratch or are you modifying a template for you have already created in excel?  I am attaching code  I used on my most recent project doing just this (based off a template though).  Please let me know if you have any specific needs (naming convention for generated forms, .xls files from scratch with formating, etc.
Dim xlApp As Excel.Application

Dim xlBook As Excel.Workbook

Dim xlSheet As Excel.Worksheet
 

xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
 

xlBook = CType(xlApp.Workbooks.Open("Ifyouhaveatemplate.xls"), Microsoft.Office.Interop.Excel.Workbook)
 

xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)

Open in new window

0
 

Author Comment

by:reeseer74
ID: 24864337
What references and import statements did you use/
0
 

Author Comment

by:reeseer74
ID: 24864350
I tryed code very similar to yours earlier and got the same error.
0
 

Author Comment

by:reeseer74
ID: 24864365
I attempting to create an instance of excel on a vb project form using a push button.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:reeseer74
ID: 24864411
Tried you code and got this:

Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
0
 
LVL 1

Expert Comment

by:xemophora
ID: 24864427
Alright just to clarify,  the direction I initially assumed was for creating an instance of excel From your vb form.  Is this correct or do you want the contents to be displayed On the form in an area?

If the first is true, after creating your form you will apply this code to the push button.  Upon pressing the button excel will open with (if specified) your sheet.  Any controls for saving the spreadsheet or modifications to this spreadsheet (ie taking data from your text boxes and adding to cells) will be done in this area as well.  Hope this helps get things rolling.
0
 
LVL 1

Assisted Solution

by:xemophora
xemophora earned 500 total points
ID: 24864513
0
 

Accepted Solution

by:
reeseer74 earned 0 total points
ID: 24871465
Hey Xemophora,
Your link worked! Many thanks!
0
 
LVL 1

Expert Comment

by:xemophora
ID: 24872872
awesome glad it worked for you.  best of luck on the rest of the project :)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now