Code addition

juneau730

Board Regular
Joined
Jun 7, 2018
Messages
111
This may not be the proper forum to ask, so I'll apologize up front, but I am hoping someone may be able to help. I have the following code extracted from a large VBScript. What I'm trying to do is add into this, a macro that was created in an excel sheet, but I am not even sure it can be done.

Code:
Sub SaveAsExcel(strFileName)	Const xlnormal = -4143
	Const xlAscending = 1
	Const xlDescending = 2
	Const xlYes = 1
	const xlSortValues = 1
	Dim oXL, objRange, objRange2
	If Not fso.FileExists(strFileName) Then WScript.Quit
	On Error Resume Next
	Set oXL = CreateObject("Excel.Application")
	
	If Err <> 0 Then 'Excel not installed
		Err.Clear
		On Error GoTo 0
		Exit Sub
	End If 


	oXL.DisplayAlerts=False ' don't display overwrite prompt.
	oXL.Workbooks.Open(strFileName)
	Set objRange = oXL.Worksheets(1).UsedRange
	Set objRange2 = oXL.Range("A2")


	objRange.Sort objRange2, xlAscending,,,,,, xlYes
	objRange.EntireColumn.Autofit()


	Dim oWS	
	Set oWS = oXL.Worksheets(1)
	oWS.Activate	
	oXL.ActiveWorkBook.SaveAs strFileName,xlnormal,,,,,,,True 'overwrite existing
	oXL.ActiveWorkBook.close
	OXL.Quit
End Sub

Excel Macro
Code:
Sub Macro1()    Columns("F:F").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("F1").Select
    ActiveCell.FormulaR1C1 = "Domain"
    Range("F2").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=MID(RC[-1],4,3)"
    Selection.AutoFill Destination:=Range("F2:F400"), Type:=xlFillDefault
    Range("F2:F400").Select
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Well, I am a little closer to a solution.

I was able to get the parent script to create a column named properly, every time the script is run and the workbook is created.

Now, I just need to figure out how to get it to populate the data needed. Some how I need to get this converted to vbs and put into the parent coding.

Code:
Sub Domain()
'
'


'
    Range("O2").Select
    ActiveCell.FormulaR1C1 = "=MID(RC[-10],4,3)"
    Selection.AutoFill Destination:=Range("O2:O400"), Type:=xlFillDefault
    Range("O2:O400").Select
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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