?
Solved

CREATING AN EXCEL SPREADSHEET IN VISUAL BASIC FORM

Posted on 2009-07-15
9
Medium Priority
?
252 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 

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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
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…

777 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