Solved

CREATING AN EXCEL SPREADSHEET IN VISUAL BASIC FORM

Posted on 2009-07-15
9
231 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Definitions and default visual studio colors 5 58
Need help on C# Linq query on object 6 53
Advice in Xamarin 21 56
Capture logon name 13 42
As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

920 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

18 Experts available now in Live!

Get 1:1 Help Now