Easy One - Calling Macro From Another
I'm writing a macro which goes through each shape, header and footer in a Word document individually and runs an external macro on it. This external macro was not written by me and I've no access to the code.
So I have the macro loop through all the objects in question and call the macro with Run, but the whole thing seems to stop running after the Run statement, and the macro appears to run on the whole document, excluding the headers and footers. Should I be using something else rather than Run?
Sub CleanWholeDocument() Dim sShape As ShapeDim fNote As FootnoteDim HeadFoot As HeaderFooterDim sSection As Section For Each sSection In ActiveDocument.Sections For Each HeadFoot In sSection.Headers HeadFoot.Range.Select Application.Run MacroName:="tw4winClean.Main" Next HeadFootNext sSection For Each fNote In ActiveDocument.Footnotes fNote.Range.Select Application.Run MacroName:="tw4winClean.Main"Next fNote For Each sShape In ActiveDocument.Shapes If sShape.TextFrame.HasText Then sShape.TextFrame.TextRange.Select Application.Run MacroName:="tw4winClean.Main" End IfNext sShape Application.Run MacroName:="tw4winClean.Main" End Sub
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Calling A Macro
How can i call a macro as soon as a form is loaded from outlook?
Calling A Macro...
I need to call ADD-IN and use one of its functions to run on a workbook that is opened from VB6.
I have noticed that when VB opens an instance of Excel it does not open the ADD-IN's that would have opened with it if it was opened as a Normal App.
How can I call this ADD-IN without having to copy its code across to the app I am writing.
Any help advice would be great....
Thanks in advance
[Edited by Rocks on 01-04-2001 at 11:43 AM]
Calling A Macro From A Macro
I am writing a macro within Excel. I want this to invoke a word object:
Dim obj As Object
Set obj = CreateObject("Word.Application")
obj.Visible = True
And then maybe load my template file, and call a macro within that. Basically, I want to create a mail merge autoamtically from the data in the Excel file at the touch of a button.
Calling A MSAccess Macro
Is there a way that I can call a MSAcess macro in a closed database from VB 6.0? Thanks for any help.
Calling An Excel Macro From VB
I've posted my code in an attempt to get some help. The line - "xl.run OverallLoop" is an attempt to call a macro in an excel application. It doesn't seem to be working. Can anyone help? ps thanks to the guys who helped before!
Dim ThisOpenPath As String, NRuns As Integer, Age As Integer
Dim VBThisFileName As String, NPats As Integer, PatAge As Integer
Dim i As Integer, j As Integer
NRuns = frmDiab.txtNRuns
NPats = frmDiab.txtNPats
ThisOpenPath = "c:PTDMMHDiab.xls"
Set xl = New Excel.Application
Application.Visible = False
Set xlWorkbook = xl.Workbooks.Open(ThisOpenPath)
Set xlWorksheet = xlWorkbook.Sheets("TherapyParams")
Set xlNumbTherapy = xlWorksheet.Range("NumbTherapy")
InitialTime = Timer
For i = 1 To NRuns
For j = 1 To 1 ' replace with xlNumbTherapy
frmDiab.lblProgress.Caption = "Run " & i & ", Therapy " & j & ""
Set xlWorkbook = xl.Workbooks.Open(ThisOpenPath)
Set xlWorksheet = xlWorkbook.Sheets("OtherParameters")
Set xlRangeDiabFlag = xlWorksheet.Range("RngDiabFlag")
Set xlRangeNPats = xlWorksheet.Range("RngVBNPats")
Set xlRangeFileName = xlWorksheet.Range("RngFileName")
Age = xlWorksheet.Range("RngAgeForVB").Value
xlRangeDiabFlag.Value = j
VBThisFileName = "Therapy" & j & "Run" & i & ""
xlRangeFileName.Value = VBThisFileName
xlRangeNPats = NPats
temptxt = "c:PTDM" & VBThisFileName & ".xls"
Set xl = Nothing
Set xlWorksheet = Nothing
Set xlWorkbook = Nothing
If Timer - InitialTime < 300 Then
ThisTimeTaken1 = Int(Timer - InitialTime)
ThisTimeTaken2 = "seconds"
ThisTimeTaken1 = Int((1 / 60) * Int(Timer - InitialTime))
ThisTimeTaken2 = "minutes"
frmDiab.RunButton.Enabled = False
frmDiab.lblProgress.Caption = "Done in " & ThisTimeTaken1 & " " & ThisTimeTaken2
frmDiab.FinishButton.Enabled = True
Calling A Macro In A Different Project
I have a macro within Excel which opens all workbooks within a specified folder. For each of these workbooks I need to call a macro that exists within the workbook.
I'm having problems getting VBA to do the call using a variable as the workbook name (the module & macro names can be specified as a constant). In fact I'm even having problems doing the external call when I explicitly write out the workbook name in the call.
Thanks for your help.
Calling A Macro From Another File
How do i call a macro from another file? For example, I want to write a macro in "c:ook1.xls" which will call a macro(sub test()) present in "d:ook1.xls".
Requesting your kind help in this regard.
Easy - Calling A Function
I have created a module containing many Public functions.
When a button is pressed on a form i want a function (say Calc01) to be called, but how do i code that. What code do i need to call that function. I'm sure it is simple!!!
Calling External Excel 4 Macro
Is it possible to call an external excel 4 macro from VB? We have a very complicated macro that doesn't seem to have an equivalent in VBA, and I need to incorporate it into my VB program...anyone have any knowledge of this?
Calling Macro In Excel From Access With Vba
Im new here, this is my first question and I hope someone out there can lend me hand or point me in the right direction. Thanks.
I have developed an Excel template with a macro in VBA. I have ten different templates which I want to fire off. At the moment, all ten is fired off from Access using a shell command, but Im finding that it uses too much virtual memory. The ten templates are all the same except using different parameters, so I am thinking of just having one template and using the Access to call up a template and passing in the parameter so the macro can act on it using that parameter. Is there a way of calling a macro function in Excel using vba?
Anyone got any advice, will be greatly appreciated.
Calling Access Macro From Excel
I have a model, running from a macro in Excel. The model cycles through hundreds of thousands of iterations for forecasting purposes. I am taking the output from the model after each iteration and dumping it into Access.
I am experiencing two problems calling the Access macro (that imports the data and places it in the appropriate table) from Excel:
1.) The database connection times out. The speed of the Excel macro is drastically reduced if I open Access after each iteration to dump data in. Therefore I have connected to Access in the beginning of my Excel macro and am only calling the Access macro after each iteration. I tried to open and close the database with each iteration, but it is time consuming and sometimes the database doesn't close which causes the program to halt.
2.) I call the Access macro in the following manner:
In the beginning of the macro the following is established:
Dim cn As New Access.Application
cn.Visible = False
Then after each iteration:
Then at the very end:
Set cn = Nothing
The problem is with the "SENDKEYS" statement. Sometimes, about 1% of the time, the macro seems to skip over the line. The macro window will open in Access prompting me to enter the macro name and "ENTER".
Any wisdom that could be imparted regarding these two issues would be greatly appreciated! Thanks for your help.
Calling Access Macro Problem
Is there anyway to keep access from popping up while doing the snippit below?
objaccess.OpenCurrentDatabase "my database"
In Excel, Calling Word Macro
Please Help, i have gotten this far and am stuck: I have an Excel Macro that copies a specific cell, and it then needs to call a Word macro to paste the contents. I know the copy/paste commands, but am having trouble calling the Word Macro. Any help would be appreciated, for i am tearing my hair out
Need Help With Calling Macro Automatically <RESOLVED>
I'm currently using vb in excel to do several tasks, although one troubles me. I would greatly appreciate some sort of insight in this matter. Im trying to print the spreadsheet at midnight. The printing is no problem, i just call on a macro to do that. The issue arises with how to call that macro at midnight. Ive tried several ways including an ondata command, but have found no way to check the time, to call the macro automatically from either the spreadsheet or a command. Any help would greatly be appreciated....
Edited by - flopro on 6/14/2004 2:18:07 PM
Install Macro's Easy
I'm programming macro's but the distribution of them is rather difficult. Each time I make an adjustment I have to let people copy the new version of the normal.dot over the old version...
What ways are there to automaticly install these modifications? Could I use an setup.exe or an other file which only has to be double clicked in order to let the new file be installed?
Easy Macro Question
How to reference a CheckBox on another worksheet.
If I have two worksheets, named Sheet1 and Sheet2 and a checkbox, (chk1) on sheet1, how do I check the value of chk1.value, while working on sheet2?
Calling Microsoft Access Module Or Macro From VB
I would like to call a Microsoft Access Module or Macro from a VB executable. This way I could schedule some database activity from my NT server.
I do not know the commands to open an Access Database (with password protection) and us the DoCmd.
Calling A Macro In Another Template In Word 2000
I am trying to call a macro in a template that I attach a run-time and the error I get keeps telling me that it is unable to run the specified macro...the code is as follows
' attach the new Signature template to override styles
.UpdateStylesOnOpen = True
.AttachedTemplate = _
"C:WINNTProfiles" + Environ("USERNAME") + "Application DataMicrosoftTemplatesSignature.dot"
Quote:THE ERROR OCCURS HERE...Should I be using another method?
' auto-run the conversion to the new look after the signature template is attached
Thanks in advance...
"Do or do not, there is no try."
Two More Easy Excel Macro Questions
i know this is pitiful, but I'm working without a helpfile...
1)Is there an easy way to see if the row is blank? What I'm doing below only checks the Active cell instead of the row.
2)If I am referencing the active cell, how do I activate the row so I can delete it?
If ActiveCell.Rows.Text = "" Then
ConsEmptyRow = ConsEmptyRow + 1
'Do something else with it
Easy Excel Macro Question
I don't have the help file on my machine, and it's been awhile since I've done this. How do I set the range property?
Dim MyRange as Range
MyRange = Activecell.range
This doesn't work because it wants more parameters for the range property.
I also tried Range(activecell), but that didn't work either.
Calling An Excel Macro From An Access Database That Refers To That Database
i have a macro in excel that inserts some values into a table in a database in access, but i want to make it so i dont have to touch the excel file, instead i have a module in the access file that calls the sub in the excel file, but then i get an error saying that the database is already open....is there a way of getting around this?
Why Wont This Work? EASY EASY EASY
Dim numbers(10) As Integer
Dim counter As Integer
Private Sub Command1_Click()
counter = 1
While counter < 10
lblDisplay = numbers(counter)
counter = counter + 1
Needs to display #'s 1 to 10 using this method
EASY EASY EASY Quesation, Just Woundering!!!
What does this mean, I see it at the top of code windows and I just woundered what it is there for. Every one probably knows this but I don't cause it isn't mentioned I any books on VB.
Word Macro Insert File/ Append Table Macro Issue.
I was wondering if someone could help me with this problem...
When I use the following code to insert a table (from an external file), the table that is inserted does not append to the table in first document (which is what I want it to do)...
Selection.InsertFile FileName:="m:cat.DOC", Link:=True
Would anyone know how I can make the contents of this file append to the table in the first document?
Thanks so much in advance,
Macro Opens A Document In Vba, Saves, Then Continue With Macro
Maybe the title isn't correct, but i've got the following problem.
I build a document that open a form. On this form there is a checkbox. When the checkbox is active and I press 'OK' a document has to be opened. On this document some changes can be made, then by pressing 'continue' this document is saved on 'c: emp' and closed. Then I want to go back to the first document and continue with it.
Is there some sort of halt or wait funtion to establish this?
The code I use is the following:
If chbFinPar = True Then
Documents.Open FileName:="f:Nieuwe format macroHuisstijlTestversiefinpar.doc"
Selection.EndKey , ActiveDocument.Bookmarks("bmkfinpar").Range
Selection.InsertFile FileName:="c: empfinpar.doc"
Private Sub cmdVrdr_Click()
ActiveDocument.SaveAs ("c: empfinpar.doc")
Word Macro Editor Opens When I Misspell A Macro Name
I'm using Word 2000, and pressing Alt+F8 to access macros - just text strings - and here's the trouble:
I'm trying to make it possible for everyone here to use Word macros from the server. I've put a file out there called Macros.dot and it works great. Every machine in the building can see it and use it. Trouble is, if a user misspells a macro name the macro editor opens by default. It doesn't realize the user has misspelled something and thinks the user wants to write a new macro under the "new" name. User can click the X to close the editor, of course, but has now created a blank macro with a name very similar to a real macro. This will drive people (especially the less tech savvy) nuts, and clog up the file Macros.dot with garbage.
Is there a way to disable the macro editor from opening if an incorrect (nonexistent) macro name is typed? A check box somewhere, perhaps? I've tried but can't seem to find it, if it's there.
Openning Excel And Running Macro From Word - Macro
Ok - I have a DB which I export to Excel, I then run a macro to "Groom The Data". I then run word and run a Macro (MailMerge to print labels) which retrieves data from the excel spreadsheet groomed above. Everything is working fine, despite my novice knowledge of VB, but I would like to do this in a single click.
I use a command line shortcut to Launch word and automatically have it run the macro, but I still have to Launch Excel and manually run its macro first.
I did not find a command line switch to make excel launch and run a macro. Is there any way I can Lauch Word have its Macro link to excel, then launch and run the excel macros before performing the macro I have set up in word (mailmerge)
In Other Words I have working macros in Word and Excel, I want the Word Macro to force the Excel macro to run before completing the rest of its duties.
How To Hide Macro Option From Tools Macro, Macros
Well, this is the situation. I created some macros (6) for a workbook. One this macros is adding a new Menu in the main Excel Menu. The idea is that the user does not need to go to options: Tools, Macros, Macro...and run the macro because I want them to do it from the menu specially created.
Also I prevented any user to edit the macros putting password if they want to see the codes.
Now How I can prevent a user to run all my macros from the option:
Tools, Macros, Macro...Can I hide a Macro from that menu?
Any way to remove this option in just this workbook not affecting the user if they want to work with a new one...?
Or may be a message saying that macro can be run from the menu if the user is trying too.
Activate Command Button Excel - EASY, EASY
This is probably as basic as questions come. I have no problems with VB coding have done plenty of that and have tested my code but now, I want my code to be executed when a command button (embedded in the worksheet) is pressed. I have created a new command button from the ActiveX Control Toolbox and placed it on my spreadsheet, BUT, when I click on it, it selects the button, allows me to resize or move it but that's not what I want. I want it to execute the Command1_Click function.
Help greatly appreciated...
Calling C++ DLL - Invalid Calling Structure
First i got a could not find entry point in DLL error. i fixed that by specifying ordinal numbers in the VB app. now when i run the program i get an invalid calling structure error and then VB Studio crashes. I think the crash is do to the threading and debugging at the same time. i have heard about problems with that. how do i fix the invalid calling structure error.
#define EXPORTMODE __declspec(dllexport)
#define EXPORTMODE __declspec(dllimport)
EXPORTMODE bool StartThread(int nTime, int nInterval);
EXPORTMODE void StopThread();
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
EXPORTMODE bool StartThread(int nTime, int nInterval)
EXPORTMODE void StopThread()
Word 200 Vba Macro Help - Enable Track Changes In A Macro. Thanks
I was able to find a macro which takes an already mail merged document, and saves each each document as a separate file. The document's filename is taken from the already merged document. The script works. It's in red. See below.
The problem is I need to enable the track changes option.I recorded the following macro. It's in blue.
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
I tried to incorporate this code(blue) into the code (red) below. I added it between ActiveDocument.Sections.First.Range.Cut and Documents.Add but it didn't work.
ActiveDocument.TrackRevisions = True
ActiveDocument.PrintRevisions = True
ActiveDocument.ShowRevisions = True
It turned on track changes but it didn't create each new document. What am I doing wrong?
Desperately Seeking help!!
Script works perfectly.
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
Letters = Selection.Information(wdActiveEndSectionNumber)
Counter = 1
While Counter < Letters
Application.ScreenUpdating = False
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:MERGELETTERS"
Docname = sPath & sName
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
ActiveDocument.SaveAs FileName:=Docname, _
Counter = Counter + 1
Application.ScreenUpdating = True
Easy Upper Case Question..or Not So Easy?
This is probably easy. Using txtfirst.text, how do I convert each letter to uppercase AS IT IS TYPED.
I am trying to use:
old = txtFirst.SelStart
txtFirst.Text = UCase(txtFirst.Text)
txtFirst.SelStart = old
But if text is entered in lowercase, it types the text backwards in uppercase.
Calling An Oracle Package.Procedure Works But Calling A Function In The Package Does Not ?
I am trying to call a function in a package in Oracle, from VB. I am using the traditional ADODB with connection, command and parameter objects. The function has 6 input parameters and it returns a string value.
We have no problems reaching the similar Procedure under a package, but when it comes to accessing the function, it gives errors. I got "no descriptor found", after some changes "object stored Procedure does not exist" .
Any suggestions on how differently to access a function within a package as opposed to a procedure ?
Call Macro ~change Macro
I want to create a print preview from a access rapport
I'm using this code:
Private Sub Command1_Click()
Dim A As Object
Set A = CreateObject("Access.Application")
A.Visible = true
A.OpenCurrentDatabase (App.Path & "
the first macrocommand is openreport + report name
at this instruction there is a posibility to specify a WHERE instruction.
Is it posible to chance this where instruction in visual basic
Run Access Macro From Excel Macro
I am using Microsoft Office 2000 and trying to run an Access macro from an Excel macro, but my Excel macro does not seem to be working. When I run the Excel macro, nothing happens - I do not get an error and the code does not do what it is suppossed to. Below is my code:
' Initialize string to database path.
Const strConPathToSamples = "C:Miscell est.mdb"
strDB = strConPathToSamples & "test.mdb"
' Create new instance of Microsoft Access.
Set appAccess = _
' Open database in Microsoft Access window.
' Run Access macro.
appAccess.DoCmd.RunMacro "Macro1", 1
I have included the references to "Microsoft DAO 3.6 Object Library" and "Microsoft Access 9.0 Object Library."
Any help on this subject would be much appreciated.
Modifying Macro Or Form With Macro
Is it possible to modify a userform or macro in a module with another macro?
I've got a database of clients that will probably have new clients from time to time. Currently using userforms to give check lists and of course that stuff is referenced in macros. Would be cool to write a macro that would allow a user to modify that stuff to add in choices as needed.
Can this be done?
Attatch A Macro To A Button With A Macro?
I am creating a new sheet using VBA, I would like to be able to add a button to this sheet (which I can do), and attach a macro to the button (which I cannot).
Can anyone tell me how to attatch a macro to a button using another macro? Or any other way of making the newly created button actually do anything?
Easy Answer To An Easy Question
I want to populate a combobox for a filelist. How can I do it?
Do Until Index = File1.ListCount
File1.listIndex = File1.listIndex + 1
Easy Maths Question (yes, Easy!)
I have two points, X1,Y1 and X2,Y2. I want to find the value from true north of X1,Y1 that X2,Y2 is.
How do I do it? I know you have to find the distance between the points, eg. X1 - X2, Y1 - Y2, but beyond that I have no idea. ;-)
If you don't know what I mean, then look here:
| is true north, / is the angle. o are the points. Ignore the .'s. =)
[Edited by git on 10-08-2000 at 05:10 AM]
Easy Easy Easy Question
This solution to this is very simple but I can't for the life of me remember it. I've been out of VB for a while.
I have the following SQL statement...
strWriteData = "INSERT INTO Clinic_Info(ID,Location_Num) " & _ " VALUES (strUniqueID,strLocation)"
When I print this to the immediate window it's sending Oracle the names strUniqueID and strLocation. I don't want it to do this, I want it to (obviously) send in the VALUES of these variables. Not the variable names!
NOTE: That code might contain a syntax error because I just typed a quick example.