Is there a way to tell the pasted content source in Word VBA? - vba

I know that MS Word allows users to choose how they want the paste to be depending on whether the pasting is from another software or same document or a different document. Is it possible to obtain that content source information from VBA? Thanks!

If you want to get information about a source of data in the clipboard, comming form outside application - sorry, it's impossible.
MSDN wrote:
The clipboard is a set of functions and messages that enable
applications to transfer data. Because all applications have access to
the clipboard, data can be easily transferred between applications or
within an application.
The function to get such of information does NOT exist!
Note: that VBA can get some information via OleAutomation (COM):
This overview does not describe how to copy and paste linked or
embedded objects. For information on these subjects, see the Component
Object Model (COM) documentation.
More information about VBA + Clipboard you can find here: Visual Basic for Applications/Clipboard VBA

Related

VBA Excel: Transfer to Word and Access

I have a program in VBA excel that manipulates data and transfers it to a few different sheets. What I would like to do now is transfer one sheet to Microsoft Access and one sheet to Microsoft Word. I would like to keep all of the code in my excel VBA workbook if possible, as opposed to Access or Word.
I want the sheet named "Data" transferred to Word and "Points" transferred to Access. I want the code to transfer these sheets to uncreated documents, then name the documents and save it. Each sheet can be transferred individually.
I have tried looking up answers to this question but have failed to find any good information! I have little idea where to begin with this specific code, so any help would be greatly appreciated.
Your question asks for to much. Books on Excel VBA like "Excel 2013 Power Programming with VBA (Mr. Spreadsheet's Bookshelf)" will help.
I will say that it will be easier for Access to pull the data from excel using it's own VBA code. To send data to word int he way you describe, will involve initialising a new word application and a new document.
Get a book, it will pay for itself as this sort of situation is often described.
Try google searche for:
"linking to excel data in an access application"
Also see:
http://www.mrexcel.com/forum/excel-questions/698670-using-excel-visual-basic-applications-export-data-ms-access-table.html
https://www.youtube.com/watch?v=PhpZQw1ktP4
And Youtube channel ExcelisFun.
Harvey

Creating Spreadsheet from SQL using ASP - Can I attach macros?

So I have been using ASP for all of a week now and perhaps this is something that I just can't do, but I am trying to dynamically generate reports from data stored in a SQL database. I am publishing the reports through an ASP document and displaying by specifying Excel for the MIME content type:
Response.Buffer = TRUE
Response.ContentType = "application/vnd.ms-excel"
Is it at all possible to "attach" macros to the document? I understand I can do basic formatting in the HTML, but I would prefer to import the desired database data and handle it within excel via macros.
EDIT:
I have several reports I need to generate but for one example:
I want to load retrieved data from the database into a sheet in excel.
Attach Macro
Begin Macro:
Hide the specified sheet.
Programatically create new sheets for categories of data.
Format sheets.
The question is not about how to program the macro, just whether or not a macro can be attached and how to achieve this. In regards to alerts upon opening the sheet, if I can attach macros I should, theoretically, be able to suppress those in the Open Workbook event.
EDIT: I believe I can achieve the desired result by using OWC (Office Web Components) (see http://support.microsoft.com/default.aspx?scid=kb;EN-US;288130). However, I am not sure if I will be able to install it on our Web Server. Any other suggestions?
While it is possible in a strictly technical sense, it is neither simple nor advisable. The recipient of the sheet will get multiple prompts related to the security of your macros; the source of your macros; and if they really, truly, honestly meant to click to enable macros...

Dump MS Access Macro object info from VBA code

I have a project in which I need to compare different versions of an Access 2003 database against each other. We're not interested in the data in the tables. We're only interested in the objects that describe the database. I.e. Form objects, Report objects, QueryDefs, TableDefs etc.. The databases are fairly large so the approach is to dump all the descriptions for objects of interest into a text file by running a VBA app in each of the databases and then comparing the results in a diff viewer.
I've been looking around for several days to find out how to dynamically dump access 2003 macro content from within VBA. Please don't confuse this with dumping VBA code from VBA.
I know about Application.CurrentDB.AllMacros to get a list of macros in the active access database. But I can't get at the macro object from Macro(MacroName).SomeProperty because the macro isn't open. So I've been trying to look for a way to open the macro and haven't found a way to accomplish this through VBA.
Any help on the topic would be appreciated.
Thanks!
You can export macros with the undocument Application.SaveAsText:
Application.SaveAsText acMacro ,"AutoKeys", "AutoKeys.txt"
...saves the AutoKeys macro to whatever the current directory is.
You could manually ask Access to convert the macros to VBA. There is an option for that, I think when you right click the macro. After that you can compare the generated VBA.
See the following page for a list of utilities to compare Access databases
http://www.granite.ab.ca/access/thirdparty.htm

How to communicate ms word and ms access in vb.net?

I want to create a program that could generate reports from an ms access database and place it on ms word, how can I do that. Please help, I dont have any idea on how to do this.
If you're doing this from vb.net, it seems to me that it would be simpler to automate Word, which has no difficulty utilizing Jet/ACE data as data source. I don't see any reason to involve the Access application in this, unless you have complex logic that needs to be executed within Access to get correct results in Word. For instance, Word doesn't do parent/child data display very well, but Access reports do that very easily.
Another question is the final disposition of the results. It may be that you don't need Word at all, e.g., if you're using Word for nothing more than generating PDFs. In that case, it might make more sense to create Access reports and output those to PDF (there's an add-in available for for A2007, and in previous versions, you can use the VB automatable PDFCreator, which is free).
In short, my conclusions would be:
if you're just merging data in Word from a Jet/ACE data store, then automate Word.
if you need to execute complex logic, it's probably better to automate Access and either output Access reports directly, or automate Word from Access.
In neither case, I believe, would you be automating both Word and Access directly from your VB.NET application.
You should connect to the Access Database using a Typed Dataset.
Right-click the project, click Add New Item, select Typed Dataset, and follow the wizard.
To control Word, add a reference to Microsoft.Office.Word and use the Application class.
You can build reports in MS Access that have the Export to Word functionality built into them.
You can invoke the report from your code and then call the export functionality and give it parameters so that it will export to a .doc file that you name. You can then invoke MS Word and open the .doc file up for display.

Exporting Excel cell data to database via Excel macro?

Can I create a macro written in C# for Excel that allows me to export a cell's data to a SQL Server or Access database?
Basically, I'd like to create a button in Excel that saves the data in certain cells to a database. Can this be done?
Instead of creating a UI from scratch for a program, I've decided using Excel as the user environment would be better for business needs.
How to automate Excel by using Visual C# to fill or to obtain data in a range by using arrays would be a good starting point.
Be aware, you're going to find it frustrating to control what people attempt to enter into the Excel sheet, as the inherit flexibility of the data works again your efforts to write it to a database destination.