I am having issues using a call function - vba

I have watched many videos on calling another sub. But with my code every time it gets to the line where it should call the function. It just finished the IF statement without following this command. Please note that this code is from a commandbutton inside of a userforum
Sub Begin_Click()
Unload BeginTheCode
Dim ws As Worksheet
Dim strDataRange As Range
Dim keyRange As Range
Dim wbk As Workbook
Dim wbkName As String
Dim wsName As String
Dim mName As String
Dim yName As String
Dim cName As String
On Error GoTo Err
'This command puts the other code in this workbook on hold'
Application.DisplayAlerts = False
'This provides shortcuts for future use in the code'
Set wa = ThisWorkbook.Worksheets("RE-I-A Raw")
Set wb = ThisWorkbook.Worksheets("I-A Data Copy (1)")
Set wc = ThisWorkbook.Worksheets("Untied Raw")
Set wd = ThisWorkbook.Worksheets("Blanks")
Dim IMRCCSpec() As String
Dim IMRSup() As String
Dim x As Integer
Dim y As Integer
Dim i As Integer
If Comittee = "IMRCC" Then
Call IM
Else
If Comittee = "COO" Then
Call COO
Else
If Comittee = "CFO" Then
Call CFO
Else
If Comittee = "AURA" Then
Call AURA
Else
If Comittee = "Distribution" Then
Call Dist
Else
If Comittee = "Legal" Then
Call Legal
End If
End If
End If
End If
End If
End If
Exit Sub
Err:
MsgBox "Error on Line : Sub Begin_Click() " & Erl
End Sub
Sub IM()
On Error GoTo Err
Dim IMRCCSpec() As String
Dim IMRSup() As String
Dim x As Integer
Dim y As Integer
x = Application.WorksheetFunction.CountA(wt.Range("C:C")) - 2
y = Application.WorksheetFunction.CountA(wt.Range("E:E")) - 2
ReDim IMRCCSpec(x) As String
ReDim IMRCCSup(y) As String
Dim i As Integer
For i = 0 To x
IMRCCSpec(i) = wt.Range("A" & i + 2)
Next i
For i = 0 To y
IMRCCSup(i) = wt.Range("B" & i + 2)
Next i
'Call Something
Exit Sub
Err:
MsgBox "Error on Line : Sub IM()" & Erl
End Sub
No error messages occur. when I use the F8 command it goes through this line without any error and does not do anything

Related

About files (.vsdx) created by Microsoft visio

I'm investigating how to automatically update a visio file created with one mastershape (v1.0.vssx) to the next version of the mastershape (v1.1.vssx). When updating each master shape, use Master.Name as the key.
With the code below, I was able to open the vsdx file and vssx and open their respective Masters.
vssx_Master = vssxMaster
vsdx_shape.master = vssx_Master
I wondered if I could update the master shape with the code, but unfortunately vssxMaster is the same as vssxMaster.Name and its type is String.
Is there a way to replace the Master of one shape with another?
not work...
Sub Visio_Update(ByRef VISIOpath As String, ByRef except_sheets() As String, ByRef VSSXpath As String)
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim vsoApp As Visio.Application
Dim vsoDoc As Visio.Document
Dim vsoPage As Visio.Page
Dim vsoItemsCnt As Long
Dim vsoShape As Visio.Shape
Dim FileName As String
Dim FileText As String
FileName = Dir(VISIOpath)
FileName = Replace(FileName, ".vsdx", "")
ChDir ThisWorkbook.path
Set vsoApp = CreateObject("Visio.Application")
Call vsoApp.Documents.OpenEx(VISIOpath, visOpenRW)
Set vsoDoc = vsoApp.Documents.Item(1)
vsoItemsCnt = vsoApp.Documents.Count
Call vsoApp.Documents.OpenEx(VSSXpath, visOpenRW)
Set vssxDoc = vsoApp.Documents.Item(vsoItemsCnt + 1)
Set vssxMasters = vssxDoc.Masters
For Each vsoPage In vsoDoc.Pages
For Each vsoShape In vsoPage.Shapes
If Not (vsoShape.Master Is Nothing) Then
On Error Resume Next
mastername = vsoShape.Master.Name
vsoShape.ReplaceShape vssxMasters.Item(vsoShape.Master.Name)
If Err.Number = 0 Then
Debug.Print ("Masters.Item")
Debug.Print "updated succeeded : ", mastername
Err.Clear
Else
Debug.Print ("Masters.Item")
Debug.Print Err.Description
Err.Clear
End If
End If
Next
Next
vsoDoc.SaveAs ThisWorkbook.path & "\data\" & FileName & "_updated_.vsdx"
Application.ScreenUpdating = True
End Sub
Sub test()
choosed_path = "C:\Users\11665307\Desktop\data\vs1.vsdx"
Update_Template = "C:\Users\11665307\Documents\test.vssx"
Call Visio_Update(choosed_path, except_sheets, (Update_Template))
End Sub
I wondered if I could update the master shape with the code
You dont need iterate all masters into stencil :)
For Each vsoPage In doc.Pages
For Each vsoShape In vsoPage.Shapes
If Not (vsoShape.Master Is Nothing) Then
vsoShape.ReplaceShape vssxMasters.Item(vsoShape.Master.Name)
End If
Next
Next
You must iterate through all the shapes on the page. If the shape was created based on the master from stencil v.1.0, then replace it with the corresponding master v.1.1. using the ReplaceShape method
Sub ttt()
Dim sh As Shape
For Each sh In ActivePage.Shapes
If sh.Master.NameU = "Circle" Then sh.ReplaceShape Application.Documents.Item("BLOCK_M.vssx").Masters.ItemU("Diamond")
Next
End Sub

VBA Excel Object Defined Error in code for exporting data to different server

I am a self-taught VBA Excel user and I am having trouble with some code that I am editing from a previous author for my needs. This code is supposed to look at a certain range of cells in the same column and export them with the respective tag in the next column over.
I keep getting an object defined error on the 29th line of the following code:
Public oServer As PISDK.Server
Public Sub SaveDataToPI()
Dim wsCurrent As Worksheet
Dim rValue As Double
Dim RowIndex As Integer
Dim strPITagName As String
Dim dtCurrent As Date
Dim blnSavedData As Boolean
'Dim bwLab As Double
'Dim bwAct As Double
'Dim bwDif As Double
'Dim MoistureLab As Double
'Dim MoistureAct As Double
'Dim MoistureDif As Double
With Application
.Cursor = xlWait
.StatusBar = "Sending Data To PI...."
.ScreenUpdating = True
End With
Set wsCurrent = ActiveSheet
With wsCurrent
'first column of data
For RowIndex = 5 To 500
If Len(EntryScreen2.Cells(RowIndex, 3).Value) < 1 Then
Exit For
End If
' Blank out error messages in column 4 if there
EntryScreen2.Cells(RowIndex, 4).Value = ""
Next
End With
With wsCurrent
'first column of data
For RowIndex = 5 To 500
If Len(EntryScreen2.Cells(RowIndex, 3).Value) < 1 Then
Exit For
End If
If Len(EntryScreen2.Cells(RowIndex, 2).Value) > 0 And Len(EntryScreen2.Cells(RowIndex, 3).Value) > 0 Then
'Save Data To PI
dtCurrent = wsCurrent.Range(wsCurrent.Cells(2, 2), wsCurrent.Cells(2, 2)).Value
Call SavePIData(EntryScreen2.Cells(RowIndex, 3).Value, EntryScreen2.Cells(RowIndex, 2).Value, dtCurrent, RowIndex)
EntryScreen2.Cells(RowIndex, 2).Value = ""
blnSavedData = True
End If
Next
End With
If blnSavedData = True Then MsgBox "Data Saved to PI, Check Column D for Errors"
With Application
.Cursor = xlDefault
.StatusBar = "Ready...."
.ScreenUpdating = True
End With
End Sub
Public Function GetServer(szServer As String) As PISDK.Server
'Dim oServer As PISDK.Server
Dim oCon As Object
Set oServer = Servers(szServer)
On Error Resume Next
If oServer.Connected = False Then
oServer.Open
End If
On Error GoTo 0
If oServer.Connected = False Then
Set oCon = CreateObject("PISDKdlg.Connections")
On Error Resume Next
oCon.Login oServer, , , False
End If
Set GetServer = oServer
End Function
Public Sub SavePIData(strPITagName As String, dblValue As Double, dtCurrent As Date, RowIndex As Integer)
Dim oTag As PIPoint
'Dim oServer As Server
On Error GoTo Error
Set oServer = GetServer("pksfpi")
Set oTag = oServer.PIPoints(strPITagName)
'Send Data to database
oTag.Data.UpdateValue dblValue, dtCurrent
Set oTag = Nothing
Exit Sub
Error:
EntryScreen2.Cells(RowIndex, 4).Value = Err.Description
End Sub
Public Sub SaveEditedDataToPI(strPITagName As String, dtCurrent As Date, dblValue As Double)
Dim oTag As PIPoint
'Dim oServer As Server
On Error Resume Next
' strPITagName , dtCurrent, rValue
Set oServer = GetServer("pksfpi")
Set oTag = oServer.PIPoints(strPITagName)
'Send Data to database
oTag.Data.UpdateValue dblValue, dtCurrent, dmReplaceOnlyDuplicates
Set oTag = Nothing
End Sub
If you find anything else wrong in my code, feel free to let me know so that I don't run into anymore problems.
Thanks!!

Compile Error - Argument Not Optional

I am getting error as Compile Error: Argument Not Optional when running vba code pointing towards the line. MsgBox (RemoveFirstChar)
Code:
Sub test()
Dim Currworkbook As Workbook
Dim CurrWKSHT As Worksheet
Dim Filename As String
Dim BCName As String
Dim Str As String
FFolder = "C:\user"
CurrLoc = "File3"
If CurrrLoc = "File3" Then
CurrLoc = FFolder & "\" & CurrLoc
Set FSobj = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set FFolderObj = FSobj.GetFolder(CurrLoc)
If Err.Number > 0 Then
'
End If
For Each BCObj In FFolderObj.Files
'BCName = Right(BCObj.Name, (Len(BCObj.Name) - InStrRev(BCObj.Name, "\", 1)))
If IsNumeric(Left(BCObj.Name, 4)) <> True Then
Call RemoveFirstChar(BCObj.Name)
'Str = RemoveFirstChar
MsgBox (RemoveFirstChar) '--->Error: Compile Error: Argument Not Optional
Else
MsgBox (BCObj.Name)
End If
Next
End If
End Sub
Public Function RemoveFirstChar(RemFstChar As String) As String
Dim TempString As String
TempString = RemFstChar
If Left(RemFstChar, 1) = "1" Then
If Len(RemFstChar) > 1 Then
TempString = Right(RemFstChar, Len(RemFstChar) - 1)
End If
End If
RemoveFirstChar = TempString
End Function
RemoveFirstChar is a user defined function that requires a non-optional string as a parameter.
Public Function RemoveFirstChar(RemFstChar As String) As String
....
End Function
I think you want to get rid of the Call RemoveFirstChar(BCObj.Name) then use,
MsgBox RemoveFirstChar(BCObj.Name)

excel vba open file runtime error 424

Excel 2010 VBA: I'm trying to loop through files in a folder and only open the files with names that contain a certain string. I've done this before and I know the logic works, but I keep getting the 424 error when I'm opening the target files. I'm pretty sure it has something to do with the links and have tried EVERYTHING to turn off those alerts problematically, but I'm still getting the error
Private Sub CommandButton1_Click()
Dim lSecurity As Long
Dim myPath As Variant
lSecurity = Application.AutomationSecurity
Application.AutomationSecurity = msoAutomationSecurityLow
Application.DisplayAlerts = False
Application.AskToUpdateLinks = False
myPath = "F:\Pathname"
Call Recurse(myPath)
Application.AutomationSecurity = lSecurity
Application.DisplayAlerts = True
Application.AskToUpdateLinks = True
End Sub
Function Recurse(sPath As Variant) As String
Dim FSO As New FileSystemObject
Dim myFolder As Folder
Dim myFile As Variant
Dim file As String
Dim A As Workbook
Dim B As Workbook
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim count As Integer
Set myFolder = FSO.GetFolder(sPath)
Set A = ThisWorkbook
i = 2
For Each myFile In myFolder.Files
If InStr(myFile.Name, "_2015_DOMESTIC_TB") <> 0 Then
Set B = Workbooks.Open(Filename:=myFile)
Call Datadump
B.Close SaveChanges:=False
End If
i = i + 1
Next
End Function
Function Datadump()
A.Cells(i, 1).Value = B.Cells(1, 4).Value
For count = 1 To 59
k = 2
A.Cells(i, k).Value = B.Cells(11 + count, 4).Value
count = count + 1
k = k + 1
Next count
End Function
Seems like your function is trying to open a non Excel file. Change your function to (Untested as posting from phone)
Function Recurse(sPath As Variant) As String
Dim FSO As New FileSystemObject
Dim myFolder As Folder
Dim myFile As Variant
Dim file As String
Dim A As Workbook, B As Workbook
Dim i As Integer, j As Integer, k As Integer, count As Integer
Dim MyAr As Variant
Set myFolder = FSO.GetFolder(sPath)
Set A = ThisWorkbook
i = 2
For Each myFile In myFolder.Files
If InStr(myFile.Name, "_2015_DOMESTIC_TB") <> 0 Then
MyAr = Split(myFile.Name, ".")
If MyAr(UBound(MyAr)) Like "xls*" Then '<~~ Check if it is an Excel file
Set B = Workbooks.Open(Filename:=myFile.Name)
Call Datadump
B.Close SaveChanges:=False
End If
End If
i = i + 1
Next
End Function
This function will check that you are trying to open a valid excel file.
If you still get the error then please tell us which line is giving you the error and what is the value of myFile.Name at the time of error.

Loop All Processes Memory

How could I, using "ReadProcessMemory" API, loop through all running processes of the machine and scan for an Array of strings and return a true/false value if any one or more are contained in the memory of the process - using VB6?
Example:
Strings() = {"#STRING1#", "#ANOTHERSTRING#", "$TRING"}
Loop # Processes
If InStr(ProcessMemory(#), Strings) Then
MsgBox(Process(#) & " Contains one of the strings!")
End If
Loop
i dont know but i used wmi in my program
something how that
Public Sub KillProcess(ByVal processName As String)
On Error GoTo ErrHandler
Dim oWMI
Dim ret
Dim sService
Dim oWMIServices
Dim oWMIService
Dim oServices
Dim oService
Dim servicename
Set oWMI = GetObject("winmgmts:")
Set oServices = oWMI.InstancesOf("win32_process")
For Each oService In oServices
servicename = LCase$(Trim$(CStr(oService.Name) & ""))
If InStr(1, servicename, LCase(processName), vbTextCompare) > 0 Then
ret = oService.Terminate
End If
Next
If Not oServices Is Nothing Then Set oServices = Nothing
If Not oWMI Is Nothing Then Set oWMI = Nothing
ErrHandler:
Err.Clear
End Sub