Solved

CREATING AN EXCEL SPREADSHEET IN VISUAL BASIC FORM

Posted on 2009-07-15
9
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Viewers will learn the different options available in the Backstage view in Excel 2013.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

724 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