I want to get the file name from an attachment inside a Purchase Requisition in SAP using VBA.
I have tried already changing the last line for some random numbers bu nothing happened and I can't manage to discover where I can get the file name.
session.findByid("wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:3212/cntlGRIDCONTROL/shellcont/shell").pressToolbarButton "&MEREQDMS"
'here my code tells me if there are any attachment in purchase requisition item
doc = session.findByid("wnd[1]/usr/tblSAPLCVOBTCTRL_DOKUMENTE/ctxtDRAW-DOKNR[1,0]").Text
'starts on item line (0)
n = 0
Do While doc <> ""
session.findByid("wnd[1]/usr/tblSAPLCVOBTCTRL_DOKUMENTE/ctxtDRAW-DOKNR[1," & n & "]").SetFocus
session.findByid("wnd[1]/usr/tblSAPLCVOBTCTRL_DOKUMENTE/ctxtDRAW-DOKNR[1," & n & "]").caretPosition = 5
'opens the attachment page with the documents inside for download
session.findByid("wnd[1]").sendVKey 2
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Application.AutomationSecurity = msoAutomationSecurityByUI
q = 1
s = 0
'num_files returns me "PDF" or "XLS".
num_files = session.findByid("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").getnodetextbypath(q)
...
Here is the file with file name I need VBA tells me ("Escopo Plataforma..."):
Please try the following.
for example:
...
'num_files returns me "PDF" or "XLS".
num_files = session.findByid("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").getnodetextbypath(q)
myFileName = session.findByid("wnd[0]/usr/tabsTAB_MAIN/tabpTSMAIN/ssubSCR_MAIN:SAPLCV110:0102/cntlCTL_FILES1/shellcont/shell/shellcont[1]/shell").getitemtext(CStr(q),"C 7")
I assume Item Name "C 7" will be different for you. This is how you determine the correct ItemName:
Record a script with the SAP GUI script recorder.
Click with the mouse in the column with the file name.
Leave the cursor there and finish the recording.
Look in the recorded script for the ItemName.
Regards, ScriptMan
Related
I need some help with vba code. I'm self-lerning so please be understanding for simply cases ;)
I'm trying to create macro which will be looking for some records/cells in one workbook (FileA) (determined by 3 conditions) and then paste values to another workbook (FileB) and after that find in another tab in FileB some values where condition will be pasted value to match them with looking value (I belivie it could be done somehow with Vlookup but I get stuck).
Below problematic for me part of code (I'm working on some files found in work, no one use it now).
First issue is with Set Update, I don't know why it takes it as "Nothing"... conditions are true - I mean "pp1" is existing in column A in FileA.
Second issue shows when I change i start range to some "later" numbers, eg From i = 2280, macro is ignoring last line where should assign some values (again shows update2 as "nothing") but value if pp2 is existing in W column in tab data...
Dim name As String
name = "[path to file on sharepoint]"
Application.ScreenUpdating = False
Workbooks.Open Filename:=name
a = 1
For i = 2263 To 14000
If Workbooks("FileA").Sheets("Main").Cells(i, 11) = "CANCEL" And Workbooks("FileA").Sheets("Main").Cells(i, 6) = "DENIS" And Workbooks("FileA").Sheets("Main").Cells(i, 5) > 1301358454 Then
pp1 = Workbooks("FileA").Sheets("Main").Cells(i, 1)
If pp1 > 0 Then
Set Update = Workbooks("FileA").Worksheets("Main").Range("A:A").Find(pp1, lookat:=xlPart)
If Update > 0 Then
Update = Update.Row
Workbooks("FileB").Worksheets("lost").Cells(a, 1).Value = Workbooks("FileA").Worksheets("Main").Cells(Update, 5)
pp2 = Workbooks("FileB").Worksheets("lost").Cells(a, 1)
update2 = Workbooks("FileB").Worksheets("data").Range("W:W").Find(pp2, lookat:=xlPart).Row
Workbooks("FileB").Worksheets("lost").Cells(a, 5) = Workbooks("FileB").Worksheets("data").Cells(update2, 43)
So I have a small VBA application that is meant to take input via a userform then send that data to a CSV file. When i read the data from the split userform textboxes the data will not format as it shows in the resulting excel file. I did some research into this and found that saving as CSV causes this to happen sometimes so i set up a script to show the value of each line in the text box and even if i don't save as a CSV the extra characters are still there. I'm hoping someone on here can tell me why this is happening.
I have tried creating a blank CSV file then writing the data to it
I have tried using a for next loop to grab all the data from the userform without saving it but the characters are still present
I have tried printing to a text file then renaming as CSV
The csv file the code generates looks great and perfect but when i copy the cells to a text file I get extra characters that should not be there. This is the output I get when copying the cells to a text file
Operation Type Full Name S ID Group ID Email Address Phone Number Extension BO Flag CFlag FFlag MD List Locale
N "Test 1
" "Test.1
" GroupTest "Test1#test.com
" "0000000000
" Yes No No en_US
N "Test 2
" "Test.2
" GroupTest "Test2#test.com
" "0000000000
" Yes No No en_US
N Test 3 Test.3 GroupTest Test3#test.com "0000000000
" Yes No No en_US
for some reason the last row is formatted correctly but I can't figure out why the rest of the rows are not
It should contain a single row for each user like the below
Operation Type Full Name S ID Group ID Email Address Phone Number Extension BO Flag CFlag FFlag MD List Locale
N Test 1 Test.1 GroupTest Test1#test.com 0000000000 Yes No No en_US
N Test 2 Test.2 GroupTest Test2#test.com 0000000000 Yes No No en_US
This is how I am pulling the data from the textbox
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox" Then
If ctrl.Name = "TextBox1" Then 'Full Name
UserForm1.TextBox1.SetFocus
LCount = UserForm1.TextBox1.LineCount
BoxValue = UserForm1.TextBox1.Text
For i = 0 To LCount - 1
BoxValue = Split(UserForm1.TextBox1, Chr(10))(i)
ActiveWorkbook.Sheets("Sheet1").Range("B" & i + 2).value = BoxValue
Next i
End If
End If
Next ctrl
This has to be something related to how I'm pulling data from the textbox but I can't find the problem.
So it turns out that all i needed to do was use a different split delimiter
I switched from:
BoxValue = Split(UserForm1.TextBox1, Chr(10))(i)
To:
BoxValue = Split(UserForm1.TextBox4, vbCrLf)(i)
This causes the split function to split at every return and now my data is perfectly formatted.
Hope this helps someone out there
I have multiple text files that are generated everyday.
I would like to search "apple" string from the latest modified text file.
If the string is not found, i will need to search from yesterday's text file.
If it still not found, i will need to search from day before yesterday's text file. The process keep going until i find the string.
Take an example:
Text file created today named : 08112018.txt
Text file created yesterday named : 08102018.txt
Text file created day before yesterday named : 08192018.txt
I will start my search for "apple" in 08112018.txt first.
If it's not found, i will search "apple" in 08102018.txt.
The process continues until "apple" is found.
Here's what I think will give you the best result:
Start by listing all your files into a disconnected record set:
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set list = CreateObject("ADOR.Recordset")
list.Fields.Append "name", 200, 255
list.Fields.Append "date", 7
list.Open
For Each f In fso.GetFolder("C:\your-folder-location").Files
list.AddNew
list("name").Value = f.Path
list("date").Value = f.DateLastModified
list.Update
Next
list.MoveFirst
You can then sort those by date last modified:
list.Sort = "date DESC"
Now you can start from the top of the list and work your way through.
Dim foundApple
list.MoveFirst
Do Until list.EOF Or foundApple
Do Until objTextFile.AtEndOfStream
Set objTextFile = fso.OpenTextFile(list("name"), ForReading)
strLine = objTextFile.ReadLine()
If InStr(strLine, "apple") <> 0 then foundApple = True
Loop
' If foundApple = True Then (Do whatever stuff you need)
list.MoveNext
Loop
list.Close
I've just brain-dumped this code. It's not tested. YMMV.
I have a problem with a select file window popping up while updating a link to an excel file. I believe it's caused by the destination file being saved at the moment I refresh the link.
I have 2 computers. I open file "A" on the first one and file "B" on the other.
File "A" runs this macro:
application.enableevents = false
Do until(I set loop for couple minutes )
Range("a1").value = 1
save
range("a1).value = 2
save
Loop
File B runs this macro:
range("b2").value = (link to File A, cell "a1")
z = 1
do until (runs for couple minutes)
Cells(z,1).value = range("b2").value
z = z+1
loop
So basically the first file continuously changes the value of cell "a1" between 1 and 2, and saves each time, while the second one constantly refreshes the link and records the linked cell value.
It works for a few rounds, then a select file window pops up.
Exact formula for the cell containing link:
"='[" & BAZAO.Name & "]" & "ZMIANY'" & "!a1"
And in excel cell it looks like that:
„='[BWP 215.xlsm]ZMIANY'!a1”
The line of code that refreshes the link:
BAZA.UpdateLink (BAZAZ.Range("C3").Value)
BAZA - name of FILE B
BAZAZ.range("c3").value - contains address and name of file A
Range("b2").value = "='[" & BAZAO.Name & "]" & "ZMIANY'" & "!a1"
„='[BWP 215.xlsm]ZMIANY'!a1”
Can anyone tell me how to suppress this select file window, or if there is any other workaround?
I think it's happening because when opening the excel file, excel creates it's copy with generated name. When changes are being saved and the original file replaced, excel deletes original file first, and then puts a temporary file in its place changing name to the original one.
I guess the select file window pops up when my macros hit between that moments.
Is this the cause?
I think I have found a workaround.
Instead of using a cell to track file avaliability I have made the code to create file "inuse.txt" in the "file A" directory whenever its in use.
Then the "file B" just checks if that file is present through dir command
I am trying to build an organization chart automatically from data in Excel using Excel VBA. It works out fine, however, I would like to have both textframes filled in. In the big textframe I would like to have filled in the description of the department, and in the smaller textframe I would have like to add the department code.
smartart hierarchy layout
I can't find the code to access the smaller textframe.
Do While Source.Cells(Line, 1) <> ""
If Source.Cells(Line, 3) = PID Then
Set ParNode = QNode
If Source.Cells(Line, 4) = 1 Then
Set QNode = QNode.AddNode(msoSmartArtNodeDefault, msoSmartArtNodeTypeAssistant)
Else: Set QNode = QNode.AddNode(msoSmartArtNodeBelow)
End If
QNode.TextFrame2.TextRange.Text = Cells(Line, 6)
'here something needs to be added !!!
CurPid = Source.Cells(Line, 2)
If Not Found Then Found = True 'something was find
'Source.Rows(Line).Delete
'Line = Line + 1
Call AddChildNodes(QNode, Source, CurPid)
Debug.Print ("CurPid" & CurPid)
Debug.Print ("line" & Line)
Set QNode = ParNode
'ElseIf Found Then 'it's sorted,so nothing else can be found
' Exit Do
'Else
End If
Line = Line + 1
Loop
the upper line (where your CEO-text is)
QNode.TextFrame2.TextRange.Text
***.SmartArt.AllNodes(...).Shapes(1).TextFrame2.TextRange.Text
the lower line where your smartart is empty:
***.SmartArt.AllNodes(...).Shapes(2).TextFrame2.TextRange.Text
you need to check if QNode.Shapes(2).TextFrame2.TextRange.Text works. if not, you may need to use .parent