473,410 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Excel: Calling Foreign Procedure

NeoPa
32,556 Expert Mod 16PB
I am setting up a public procedure which I plan to have available to all open workbooks. Technically, it sets the column formatting for any column in other workbooks, which matches any of the field names listed in my library workbook (which also contains the procedure). This comes about because copying data from SQL Management Studio and pasting into Excel doesn't maintain any info about the data. Access works more intuitively. If I copy in data that is textual, but contains all digits, it knows to maintain the data as text. Unfortunately, from SQL Management Studio it doesn't.

It may well be a clumsy way of going about this, but I'm looking for the syntax I would need to use to say :
I want to call procedure A from loaded workbook B (from code or even the Immediate Pane of the IDE).

I will consider all solutions of course, but I'm interested in the specific answer to the question, regardless of whether or not it is the best solution in this case.
Sep 7 '10 #1
2 1685
TheSmileyCoder
2,322 Expert Mod 2GB
Maybe im miss-understanding what your trying to achieve, but why not create this as an excel add-in? That way it will be available each time you open Excel (Assuming the add-in is installed on the PC)

For a quick guide on how to make an add in:
Excel Add In

You can then add it to a toolbar (to autoload) if you want.
Sep 7 '10 #2
NeoPa
32,556 Expert Mod 16PB
I will certainly explore this further Smiley. I'm interested in creating Add-Ins (I've not done any yet), but I'm also interested in the structure of calling a routine from another project.

It seems (after further reading and digging in various places) that there are fundamentally two ways of calling routines within Excel :
  1. Calling like a macro. This can be done by the operator directly, or by using Application.Run from code. Not much good for function procedures, but does give access to any workbook, loaded or not.

    The format of the macro parameter string requires the optional file name to be specified with single-quotes (') if it contains any ambiguous characters (space, dot, etc) follwed by the exclamation mark (!) then, optionally again, the name of the project (This defaults to VBAProject) and then a dot followed by the name of the procedure itself. For example, my routine would be called thusly :
    Expand|Select|Wrap|Line Numbers
    1. Call Application.Run("'U:\Excel\Code\SQLFields.Xls'!VBAProject.ColumnFormats")
    NB. If this is run infrequently it can easily be left unloaded in the normal course of events.
    If loaded, and there is only one instance of the procedure in the project (true in almost all cases) then it can be simplified to :
    Expand|Select|Wrap|Line Numbers
    1. Call Application.Run("'SQLFields.Xls'!ColumnFormats")
  2. Calling the procedure directly from code and using it in a way that's very similar to calling a procedure that's available in the current project. It seems this requires a Reference to be set up before it can work. More complicated than I need for this particular situation, but worth bearing in mind for more fundamental code probably.
Sep 7 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: dw | last post by:
Hello all, I'm having a dickens of a time calling a stored procedure on a connection. Every time I do, it generates an error "Arguments are of the wrong type, are out of acceptable range, or are in...
5
by: p_le_sueur_1 | last post by:
Dear All, This is a query surrounding a problem I encountered yesterday. In SQL Server, it is possible to write a procedure that has one or more select statements in it. The results from...
0
by: JN | last post by:
Hello, I'm having problem calling stored procedures from Visual FoxPro database. I got the following exception error: "System.Data.OleDb.OleDbException: Unrecognized command verb" It seems...
6
by: Scott McNair | last post by:
Hi all, I'm having problems calling a stored procedure from within my code. If I execute the SP manually from a Query Analyzer window it runs without a hitch, but it seems it doesn't even fire...
0
by: franjorge | last post by:
Hi, I have created two stored procedures via VB using this code: sql = "CREATE PROC " & nombre_proc & " AS SELECT *" & _ " From MBM_PUNTOS_SCE_SIN_COINCIDIR_SIEGE_FALTA_PM_NE_" & mes & _ "...
4
by: Jack | last post by:
Hi, I am trying to run an example code from a book. However I am getting the following error message: Number: -2147217900 Description: Syntax error or access violation Source: Microsoft OLE...
1
by: Gerald Klix | last post by:
I read the whol email thread carefully and could not find any sentence by Guido, which states that he does not accept ctypes for the standard library. He just declined to rewrite winreg. Did I miss...
14
by: krishna1412 | last post by:
Currently i am working in a project of report generation in MS ACCESS. The tables are in sql server 2000. I have to write stored proc in ms access. Illustration: I am having a stored proc...
4
by: eighthman11 | last post by:
I'm calling a stored procedure on a sql server from an access application. I just need the stored procedure to run I do not need any data returned from the stored procedure to my Access...
6
Soniad
by: Soniad | last post by:
Hello, I am excecuting a stored procedure in my ASP page , it has one out parameter (@confirm) . after executing the procedure i want to retreive this out parameter and assign it to variable...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.