vba and vbs file name import

Epidural

New Member
Joined
Mar 12, 2019
Messages
3
Dear All,

I have an issue with the following
I have a code that saves a file under a name from one of the cells:

Rich (BB code):
Sub zapisintemp()
'
' zapisintemp Macro
'
Dim Path As String
Dim filename As String

'
   Range("A1:H1").Select
   Range(Selection, Selection.End(xlDown)).Select
   Selection.Copy
   Workbooks.Add
   ActiveSheet.Paste
   Cells.Select
   Cells.EntireColumn.AutoFit
   Range("A1").Select
   Application.CutCopyMode = False
   Path = "M:\timeless\exprecup\inventar\IN_temp\import"
   filename = Range("E1")
   ActiveWorkbook.SaveAs filename:=Path & filename &".xls", FileFormat:=xlNormal

End Sub

And another macro that uses a vbs file that converts the file from xls to PAQ ( I use it to transfer data to SAP):
It’s working with a fixed path.

Rich (BB code):
Sub exceltopaq()
'
' exceltopaq Macro
'
 Dim VBScriptFile As String
 Dim scriptArg As String


    scriptArg ="C:\Users\x\Documents\makro\050319_4P92.xls"  

    VBScriptFile ="C:\Users\x\Documents\makro\PAQ_converter.vbs"   

    Shell "wscript " &Q(VBScriptFile) & " " & Q(scriptArg), vbNormalFocus

End Sub


Private FunctionQ(text As String) As String
    Q = Chr(34) & text & Chr(34)
End Function


And now my question is. How to write the code for the second macro to take the file saved from the first macro?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
There are at least 2 ways to do it, depending on your workflow.
One way is to make the first Sub a function and call it within the second one:
Code:
Function zapisintemp() As String
Dim Path As String
Dim filename As String
   Range("A1:H1").Select
   Range(Selection, Selection.End(xlDown)).Select
   Selection.Copy
   Workbooks.Add
   ActiveSheet.Paste
   Cells.Select
   Cells.EntireColumn.AutoFit
   Range("A1").Select
   Application.CutCopyMode = False
   Path = "M:\timeless\exprecup\inventar\IN_temp\import"
   filename = Range("E1")
   ActiveWorkbook.SaveAs filename:=Path & filename &".xls", FileFormat:=xlNormal
   zapisintemp = Path & filename &".xls"
End Function

Sub exceltopaq()
 Dim VBScriptFile As String
 Dim scriptArg As String
    scriptArg =zapisintemp  
    VBScriptFile ="C:\Users\x\Documents\makro\PAQ_converter.vbs"   
    Shell "wscript " &Q(VBScriptFile) & " " & Q(scriptArg), vbNormalFocus
End Sub

The second way is to set a string type variable - the first sub puts the filename into the variable, the second gets it from it.
 
Upvote 0
You're welcome.
I'm glad it worked.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top