473,563 Members | 2,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to run a Macro in Excel using a macro started in word

1 New Member
Hi guys. I am trying to fuly automate a cut and paste operation. Basically the data is dragged off the net, formatted using a macro in word then copied from word and pasted into Excel.

From there I have an Excel macro called "FinalStep" which converts the data into a table format.

the trouble is I cannot get the macro to run at all. The code is posted below.

Sub LastStepTest()
'Macro purpose: Use the application.run method to execute
'a macro without arguments from another workbook

Dim PathToFile As String, _
NameOfFile As String, _
wbTarget As Workbook, _
CloseIt As Boolean

'Set file name and location. You will need to update this info!
NameOfFile = "Personal.x ls"
PathToFile = "H:\profile\App lication Data\Microsoft\ Excel\XLSTART\"
'Macro purpose: Use the application.run method to execute
'a macro without arguments from another workbook
'Attempt to set the target workbook to a variable. If an error is
'generated, then the workbook is not open, so open it
On Error Resume Next
Set wbTarget = Workbooks(NameO fFile)

If Err.Number <> 0 Then
'Open the workbook
Err.Clear
Set wbTarget = Workbooks.Open( PathToFile & "\" & NameOfFile)
CloseIt = True
End If

'Check and make sure workbook was opened
If Err.Number = 1004 Then
MsgBox "Sorry, but the file you specified does not exist!" _
& vbNewLine & PathToFile & "\" & NameOfFile
Exit Sub
End If
On Error GoTo 0

'Run the macro! (You will need to update "MacroName" to the
'name of the macro you wish to run)
Application.Run (wbTarget.Name & "!FinalStepTest ")

If CloseIt = True Then
'If the target workbook was opened by the macro, close it
wbTarget.Close savechanges:=Fa lse
Else
'If the target workbook was already open, reactivate this workbook
ThisWorkbook.Ac tivate
End If

End Sub

I realise that not all of this code is required but as I am new to this I am not sure what to cut out. Either way the error I am getting is "run time error Unable to run the specified macro" and this line is highlighted in yellow: Application.Run (wbTarget.Name & "!FinalStepTest ")

Thanks for your help, I have been on this all day!

Michael
I know that more is required of the Application
Mar 4 '11 #1
0 1223

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

Similar topics

1
2039
by: shinde.shailesh | last post by:
Hi All, I have an xls file which contains data in one column. Also Having .MDB file with Table name "TableTest" and one field "Tabletst". I ahve to extract data from xls to MDB using Macro. Can anyone provide me references or examples ffro the same.
2
12442
by: musa.biralo | last post by:
Hi, i want to read each row of specific column of musa.dbf using macro (VBA) in excel. my main gole is to copy the data of dbf file to excel file. I am new but want to do something..i tried and tried...and finally i am here.... help me. musa.biralo
0
1572
by: guptasourav | last post by:
I am opening an Excel file on my server, and saving it with some other name and then trying to coping the new excel to my local machine. If i use a simple Excel(without macro but with password) it works properly but if i use a macro and make the excel password protected then it does not allow me to open it. It does not give any exception but...
2
4960
by: santuvssantu | last post by:
Hi Friends, I have tried inserting an excel file to a word document.But the following code is inserting the junk information. So can you please help me out? Dim m_WordApp As New Word.Application Dim m_WordDoc As Word.Document m_WordDoc = m_WordApp.Documents.Open(CObj("C:\Documents and Settings\santu\My...
1
4126
by: idealfellow | last post by:
Hi All, I need to delete entire column(GB) in excel using ruby code. let me whether i should write some ruby code or is there a way to call an excel macro from ruby whichever is simpler or easy way to maintain. cheers
3
4614
by: atiullah | last post by:
I want to insert a picture in the background of the plot area in ms excel using visual basic macro...How can it be done..Please help
0
1036
by: J5lemonade | last post by:
I'm not sure my question was placed in the correct section: http://bytes.com/topic/visual-basic/answers/888933-how-use-access-db-through-excel-vba-macro
7
3519
by: alphanj | last post by:
Hi I need a code for a macro to select every 3rd word after selection.
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.