Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CREATING AN EXCEL SPREADSHEET IN VISUAL BASIC FORM

Posted on 2009-07-15
9
Medium Priority
?
285 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

Author Comment

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

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 2000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

824 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