Support
Quality
Security
License
Reuse
Coming Soon for all Libraries!
Currently covering the most popular Java, JavaScript and Python libraries. See a SAMPLE HERE.
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Fault tolerance and resilience patterns for the JVM
How to search for latest file in folder and if not found then open dialog box with restrictions
Sub ImportAndFormatData()
Dim fSelected As String, wb As Workbook
fSelected = InputFile()
If Len(fSelected) > 0 Then
Set wb = Workbooks.Open(fSelected)
wb.Sheets("Analyse").Copy After:=ThisWorkbook.Sheets("PR11_P3")
wb.Close False
End If
End Sub
Function InputFile() As String
Const SRC_FOLDER As String = "C:\Temp\"
Dim f, fSelected As String, latestDate As Date, fdt
f = Dir(SRC_FOLDER & "*_pr11*.xlsx") 'first check the configured folder for a match
If Len(f) > 0 Then
'found matching file at specified path: loop for the newest file
Do While Len(f) > 0
fdt = FileDateTime(SRC_FOLDER & f)
If fdt > latestDate Then
fSelected = SRC_FOLDER & f
latestDate = fdt
End If
f = Dir()
Loop
InputFile = fSelected
Else
'no match at specified path - allow user selection
With Application.FileDialog(msoFileDialogFilePicker)
.Filters.Clear
.Title = "Välj valfri PR11"
.Filters.Add "Excel filer", "*.xlsx" 'filter only allows extension: no filename wildcards...
.AllowMultiSelect = False
If .Show Then InputFile = .SelectedItems(1)
End With
End If
End Function
java.lang.RuntimeException: not supported: class org.spockframework.gentyref.CaptureTypeImpl
public class Foo {
public ResponseEntity<?> bar(Long id) {
...
}
}
setup:
Foo mockFoo = Stub()
given:
String id = '123'
and:
ResponseEntity<String> response = new ResponseEntity<String>('Hello World', HttpStatus.OK)
and:
mockFoo.bar(id) >> response
...
then:
mockFoo.bar(id) >> response
0 * _ // don't allow any other interaction
Handler dispatch failed; nested exception is Too many invocations for:
0 * _ // don't allow any other interaction (1 invocation)
-----------------------
public class Foo {
public ResponseEntity<?> bar(Long id) {
...
}
}
setup:
Foo mockFoo = Stub()
given:
String id = '123'
and:
ResponseEntity<String> response = new ResponseEntity<String>('Hello World', HttpStatus.OK)
and:
mockFoo.bar(id) >> response
...
then:
mockFoo.bar(id) >> response
0 * _ // don't allow any other interaction
Handler dispatch failed; nested exception is Too many invocations for:
0 * _ // don't allow any other interaction (1 invocation)
-----------------------
public class Foo {
public ResponseEntity<?> bar(Long id) {
...
}
}
setup:
Foo mockFoo = Stub()
given:
String id = '123'
and:
ResponseEntity<String> response = new ResponseEntity<String>('Hello World', HttpStatus.OK)
and:
mockFoo.bar(id) >> response
...
then:
mockFoo.bar(id) >> response
0 * _ // don't allow any other interaction
Handler dispatch failed; nested exception is Too many invocations for:
0 * _ // don't allow any other interaction (1 invocation)
-----------------------
public class Foo {
public ResponseEntity<?> bar(Long id) {
...
}
}
setup:
Foo mockFoo = Stub()
given:
String id = '123'
and:
ResponseEntity<String> response = new ResponseEntity<String>('Hello World', HttpStatus.OK)
and:
mockFoo.bar(id) >> response
...
then:
mockFoo.bar(id) >> response
0 * _ // don't allow any other interaction
Handler dispatch failed; nested exception is Too many invocations for:
0 * _ // don't allow any other interaction (1 invocation)
Why do I keep getting a Runtime Error with this script?
# load modules
from multiprocessing.dummy import freeze_support
from socket import if_nameindex
from subprocess import call
from urllib.request import urlopen
from time import sleep as sleep
import selenium.webdriver.common.alert
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.support import expected_conditions as EC
import undetected_chromedriver.v2 as uc
import pyautogui as pag
import random
import PIL
pag.PAUSE = 0.75
pag.FAILSAFE = True
# Setup undetected webdriver - Chrome
driver = None
# Login to Gmail
def gmail_login():
driver.get('https://accounts.google.com/signin/v2/challenge/pwd?service=mail&passive=1209600&osid=1&continue=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F%3Fhl%3Den-GB&followup=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F%3Fhl%3Den-GB&hl=en-GB&emr=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin&cid=1&navigationDirection=forward&TL=AM3QAYYUTnRXTuWE8Im5D6c1ck-DYnhDNwQZdU2z8S1Cp5HzEXXCQxi5OGQuA87M')
driver.implicitly_wait(15)
sleep(5)
driver.maximize_window()
sleep(3)
# Gmail credentials
username = "XXXX@gmail.com"
password = "XXXXX"
# find email input and insert email
driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[1]/div/form/span/section/div/div/div[1]/div/div[1]/div/div[1]/input").send_keys(username)
sleep(2)
# click next button
driver.find_element_by_xpath('//*[@id="identifierNext"]/div/button/span').click()
# enter password
sleep(2)
passWordBox = driver.find_element_by_xpath(
'//*[@id ="password"]/div[1]/div / div[1]/input')
passWordBox.send_keys(password)
sleep(2)
nextButton = driver.find_elements_by_xpath('//*[@id ="passwordNext"]')
nextButton[0].click()
driver.implicitly_wait(10)
sleep(35)
promotions()
# Select Promotion Tab
def promotions():
x, y = pag.locateCenterOnScreen(r'C:\Users\New User\AppData\Local\Programs\Python\Python39\60 Second Traffic\promotions_tab.PNG', confidence=0.7)
pag.click(x, y)
sleep(3)
email_open()
# Select Email To Open
def email_open():
i = 0
while i<30:
x, y = pag.locateCenterOnScreen(r'C:\Users\New User\AppData\Local\Programs\Python\Python39\60 Second Traffic\earncredits.PNG', confidence=0.7)
pag.click(x, y)
sleep(3)
# click credit link
x, y = pag.locateCenterOnScreen(r'C:\Users\New User\AppData\Local\Programs\Python\Python39\60 Second Traffic\click_link_blue.PNG', confidence=0.7)
sleep(3)
driver.maximize_window()
sleep(15)
driver.close()
i += 1
else:
sleep(3)
print('Finshed on ' + i)
sleep(2)
# driver.quit()
#bottom of page
if __name__ == '__main__':
driver = uc.Chrome()
gmail_login()
How to correct code so that it runs or inserts formula in column to left of Range for cells that = "Metered"
For Each cell In bng
If Value = "Metered" Then
bng.Offset(0, -1).Select
Selection.Value = "S & ActiveCell.Row)"
Else
End If
Next
For Each cell In bng
If cell.Value = "Metered" Then
cell.Offset(0, -1).Value = cell.Worksheet.Range("S" & cell.Row).Value
End If
Next
-----------------------
For Each cell In bng
If Value = "Metered" Then
bng.Offset(0, -1).Select
Selection.Value = "S & ActiveCell.Row)"
Else
End If
Next
For Each cell In bng
If cell.Value = "Metered" Then
cell.Offset(0, -1).Value = cell.Worksheet.Range("S" & cell.Row).Value
End If
Next
-----------------------
cell.EntireRow.Columns("C").Value = cell.EntireRow.Columns("S").Value
Sub MeteredLookupRefreshFormulaQuickFix()
With Sheet1
.Unprotect Password:="Cami8"
With .Range("D8:D10009")
Dim cell As Range
For Each cell In .Cells
If StrComp(CStr(cell.Value), "Metered", vbTextCompare) = 0 Then
cell.Offset(0, -1).Value = cell.EntireRow.Columns("S").Value
End If
Next cell
End With
.Protect Password:="Cami8"
End With
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Refreshes...
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Calls: RefColumn,GetRange.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub MeteredLookupRefreshFormula()
Const cfcAddress As String = "D8"
Const dCol As String = "C"
Const sCol As String = "S"
Const Criteria As String = "Metered"
Const pw As String = "Cami8"
Sheet1.Unprotect Password:=pw
Dim crg As Range: Set crg = RefColumn(Sheet1.Range(cfcAddress))
If crg Is Nothing Then Exit Sub ' no data
Dim cData As Variant: cData = GetRange(crg)
Dim drg As Range: Set drg = crg.EntireRow.Columns(dCol)
Dim dData As Variant: dData = GetRange(drg)
Dim sData As Variant: sData = GetRange(crg.EntireRow.Columns(sCol))
Dim r As Long
For r = 1 To UBound(cData, 1)
If StrComp(CStr(cData(r, 1)), Criteria, vbTextCompare) = 0 Then
dData(r, 1) = sData(r, 1)
End If
Next r
drg.Value = dData
Sheet1.Protect Password:=pw
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Creates a reference to the one-column range ('crg') whose first
' cell is defined by the first cell of the range ('FirstCell')
' and whose last cell is the bottom-most non-empty cell
' of the first cell's worksheet column.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function RefColumn( _
ByVal FirstCell As Range) _
As Range
Const ProcName As String = "RefColumn"
On Error GoTo ClearError
With FirstCell.Cells(1)
Dim lCell As Range
Set lCell = .Resize(.Worksheet.Rows.Count - .Row + 1) _
.Find("*", , xlFormulas, , , xlPrevious)
If lCell Is Nothing Then Exit Function
Set RefColumn = .Resize(lCell.Row - .Row + 1)
End With
ProcExit:
Exit Function
ClearError:
Debug.Print "'" & ProcName & "' Run-time error '" _
& Err.Number & "':" & vbLf & " " & Err.Description
Resume ProcExit
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Returns the values of a range ('rg') in a 2D one-based array.
' Remarks: If ˙rg` refers to a multi-range, only its first area
' is considered.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function GetRange( _
ByVal rg As Range) _
As Variant
Const ProcName As String = "GetRange"
On Error GoTo ClearError
If rg.Rows.Count + rg.Columns.Count = 2 Then ' one cell
Dim Data As Variant: ReDim Data(1 To 1, 1 To 1): Data(1, 1) = rg.Value
GetRange = Data
Else ' multiple cells
GetRange = rg.Value
End If
ProcExit:
Exit Function
ClearError:
Debug.Print "'" & ProcName & "' Run-time error '" _
& Err.Number & "':" & vbLf & " " & Err.Description
Resume ProcExit
End Function
-----------------------
cell.EntireRow.Columns("C").Value = cell.EntireRow.Columns("S").Value
Sub MeteredLookupRefreshFormulaQuickFix()
With Sheet1
.Unprotect Password:="Cami8"
With .Range("D8:D10009")
Dim cell As Range
For Each cell In .Cells
If StrComp(CStr(cell.Value), "Metered", vbTextCompare) = 0 Then
cell.Offset(0, -1).Value = cell.EntireRow.Columns("S").Value
End If
Next cell
End With
.Protect Password:="Cami8"
End With
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Refreshes...
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Calls: RefColumn,GetRange.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub MeteredLookupRefreshFormula()
Const cfcAddress As String = "D8"
Const dCol As String = "C"
Const sCol As String = "S"
Const Criteria As String = "Metered"
Const pw As String = "Cami8"
Sheet1.Unprotect Password:=pw
Dim crg As Range: Set crg = RefColumn(Sheet1.Range(cfcAddress))
If crg Is Nothing Then Exit Sub ' no data
Dim cData As Variant: cData = GetRange(crg)
Dim drg As Range: Set drg = crg.EntireRow.Columns(dCol)
Dim dData As Variant: dData = GetRange(drg)
Dim sData As Variant: sData = GetRange(crg.EntireRow.Columns(sCol))
Dim r As Long
For r = 1 To UBound(cData, 1)
If StrComp(CStr(cData(r, 1)), Criteria, vbTextCompare) = 0 Then
dData(r, 1) = sData(r, 1)
End If
Next r
drg.Value = dData
Sheet1.Protect Password:=pw
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Creates a reference to the one-column range ('crg') whose first
' cell is defined by the first cell of the range ('FirstCell')
' and whose last cell is the bottom-most non-empty cell
' of the first cell's worksheet column.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function RefColumn( _
ByVal FirstCell As Range) _
As Range
Const ProcName As String = "RefColumn"
On Error GoTo ClearError
With FirstCell.Cells(1)
Dim lCell As Range
Set lCell = .Resize(.Worksheet.Rows.Count - .Row + 1) _
.Find("*", , xlFormulas, , , xlPrevious)
If lCell Is Nothing Then Exit Function
Set RefColumn = .Resize(lCell.Row - .Row + 1)
End With
ProcExit:
Exit Function
ClearError:
Debug.Print "'" & ProcName & "' Run-time error '" _
& Err.Number & "':" & vbLf & " " & Err.Description
Resume ProcExit
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Returns the values of a range ('rg') in a 2D one-based array.
' Remarks: If ˙rg` refers to a multi-range, only its first area
' is considered.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function GetRange( _
ByVal rg As Range) _
As Variant
Const ProcName As String = "GetRange"
On Error GoTo ClearError
If rg.Rows.Count + rg.Columns.Count = 2 Then ' one cell
Dim Data As Variant: ReDim Data(1 To 1, 1 To 1): Data(1, 1) = rg.Value
GetRange = Data
Else ' multiple cells
GetRange = rg.Value
End If
ProcExit:
Exit Function
ClearError:
Debug.Print "'" & ProcName & "' Run-time error '" _
& Err.Number & "':" & vbLf & " " & Err.Description
Resume ProcExit
End Function
-----------------------
cell.EntireRow.Columns("C").Value = cell.EntireRow.Columns("S").Value
Sub MeteredLookupRefreshFormulaQuickFix()
With Sheet1
.Unprotect Password:="Cami8"
With .Range("D8:D10009")
Dim cell As Range
For Each cell In .Cells
If StrComp(CStr(cell.Value), "Metered", vbTextCompare) = 0 Then
cell.Offset(0, -1).Value = cell.EntireRow.Columns("S").Value
End If
Next cell
End With
.Protect Password:="Cami8"
End With
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Refreshes...
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Calls: RefColumn,GetRange.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub MeteredLookupRefreshFormula()
Const cfcAddress As String = "D8"
Const dCol As String = "C"
Const sCol As String = "S"
Const Criteria As String = "Metered"
Const pw As String = "Cami8"
Sheet1.Unprotect Password:=pw
Dim crg As Range: Set crg = RefColumn(Sheet1.Range(cfcAddress))
If crg Is Nothing Then Exit Sub ' no data
Dim cData As Variant: cData = GetRange(crg)
Dim drg As Range: Set drg = crg.EntireRow.Columns(dCol)
Dim dData As Variant: dData = GetRange(drg)
Dim sData As Variant: sData = GetRange(crg.EntireRow.Columns(sCol))
Dim r As Long
For r = 1 To UBound(cData, 1)
If StrComp(CStr(cData(r, 1)), Criteria, vbTextCompare) = 0 Then
dData(r, 1) = sData(r, 1)
End If
Next r
drg.Value = dData
Sheet1.Protect Password:=pw
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Creates a reference to the one-column range ('crg') whose first
' cell is defined by the first cell of the range ('FirstCell')
' and whose last cell is the bottom-most non-empty cell
' of the first cell's worksheet column.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function RefColumn( _
ByVal FirstCell As Range) _
As Range
Const ProcName As String = "RefColumn"
On Error GoTo ClearError
With FirstCell.Cells(1)
Dim lCell As Range
Set lCell = .Resize(.Worksheet.Rows.Count - .Row + 1) _
.Find("*", , xlFormulas, , , xlPrevious)
If lCell Is Nothing Then Exit Function
Set RefColumn = .Resize(lCell.Row - .Row + 1)
End With
ProcExit:
Exit Function
ClearError:
Debug.Print "'" & ProcName & "' Run-time error '" _
& Err.Number & "':" & vbLf & " " & Err.Description
Resume ProcExit
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Returns the values of a range ('rg') in a 2D one-based array.
' Remarks: If ˙rg` refers to a multi-range, only its first area
' is considered.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function GetRange( _
ByVal rg As Range) _
As Variant
Const ProcName As String = "GetRange"
On Error GoTo ClearError
If rg.Rows.Count + rg.Columns.Count = 2 Then ' one cell
Dim Data As Variant: ReDim Data(1 To 1, 1 To 1): Data(1, 1) = rg.Value
GetRange = Data
Else ' multiple cells
GetRange = rg.Value
End If
ProcExit:
Exit Function
ClearError:
Debug.Print "'" & ProcName & "' Run-time error '" _
& Err.Number & "':" & vbLf & " " & Err.Description
Resume ProcExit
End Function
updating dns CNAME
$rs = Get-AzDnsRecordSet -name "rahul" -RecordType CNAME -ZoneName "zone.com" -ResourceGroupName "rgname"
Remove-AzDnsRecordConfig -RecordSet $rs -Cname $rs.Records.cname | Set-AzDnsRecordSet
$newcname = "new-test-v1.com"
Get-AzDnsRecordSet -name "rahul" -RecordType CNAME -ZoneName "myzone.com" -ResourceGroupName "rgname" | Add-AzDnsRecordConfig -Cname $newcname | Set-AzDnsRecordSet
-----------------------
$rs.Records[0].cname = "new-test-v1.com"
$rs.Records[0].Records = "new-test-v1.com"
$rs = Get-AzDnsRecordSet -name "test1" -RecordType CNAME -ZoneName "zone.io" -ResourceGroupName "dns"
$rs.Records[0].Records = "new-test-v1.com"
Set-AzDnsRecordSet -RecordSet $rs
-----------------------
$rs.Records[0].cname = "new-test-v1.com"
$rs.Records[0].Records = "new-test-v1.com"
$rs = Get-AzDnsRecordSet -name "test1" -RecordType CNAME -ZoneName "zone.io" -ResourceGroupName "dns"
$rs.Records[0].Records = "new-test-v1.com"
Set-AzDnsRecordSet -RecordSet $rs
-----------------------
$rs.Records[0].cname = "new-test-v1.com"
$rs.Records[0].Records = "new-test-v1.com"
$rs = Get-AzDnsRecordSet -name "test1" -RecordType CNAME -ZoneName "zone.io" -ResourceGroupName "dns"
$rs.Records[0].Records = "new-test-v1.com"
Set-AzDnsRecordSet -RecordSet $rs
error when connecting local mysql to gitlab ci/cdpipeline
services:
- docker:dind
- mysql:8
url: jdbc:mysql://localhost:3306/usermanagementdb?createDatabaseIfNotExist=true
url: jdbc:mysql://mysql:3306/usermanagementdb?createDatabaseIfNotExist=true
-----------------------
services:
- docker:dind
- mysql:8
url: jdbc:mysql://localhost:3306/usermanagementdb?createDatabaseIfNotExist=true
url: jdbc:mysql://mysql:3306/usermanagementdb?createDatabaseIfNotExist=true
-----------------------
services:
- docker:dind
- mysql:8
url: jdbc:mysql://localhost:3306/usermanagementdb?createDatabaseIfNotExist=true
url: jdbc:mysql://mysql:3306/usermanagementdb?createDatabaseIfNotExist=true
Launching chrome in headless mode with selenium in Java giving error
System.setProperty("webdriver.chrome.driver", "src/main/extras/chromedriver.exe");
WebDriverManager.chromedriver().setup();
Exception in thread "Thread-3" java.lang.NullPointerException
-----------------------
System.setProperty("webdriver.chrome.driver", "src/main/extras/chromedriver.exe");
WebDriverManager.chromedriver().setup();
Exception in thread "Thread-3" java.lang.NullPointerException
-----------------------
System.setProperty("webdriver.chrome.driver", "src/main/extras/chromedriver.exe");
WebDriverManager.chromedriver().setup();
Exception in thread "Thread-3" java.lang.NullPointerException
Test are not executed during build time
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
How to append unappended rows of data from a source sheet to a target sheet, then mark as APPENDED to prevent duplicate appending
/** @OnlyCurrentDoc*/
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sourceSheet = ss.getSheetByName("NEWDATA");
const targetSheet = ss.getSheetByName("ALLDATA");
const startRow = 2; // First row of data to process
const APPENDED = 'APPENDED';
function appendToRecords() {
const numRows = sourceSheet.getLastRow() - 1; // Number of rows to process
const dataRange = sourceSheet.getRange(startRow, 1, numRows, sourceSheet.getLastColumn()); // Fetch the range of cells being used
const sourceData = dataRange.getValues(); // Fetch values for each row in the Range.
const lastColumn = sourceData[0].length;
for (var i = 0; i < sourceData.length; ++i) {
var row = sourceData[i];
if (row[lastColumn-1] != APPENDED) {
///you should not do this line by line, but all at oncw with an array
row[lastColumn-1] = APPENDED;
var lastRow = targetSheet.getLastRow();
targetSheet.getRange(lastRow + 1, 1, 1, row.length).setValues([row]);
sourceSheet.getRange(startRow + i, lastColumn).setValue("APPENDED");
}
}
}
running SpringBootTest using a spring profile given by maven
-Dspring.profiles.active=local
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dspring.profiles.active=local</argLine>
</configuration>
</plugin>
<profile>
<id>local</id>
<properties>
<myProfiles>local,foo,bar</myProfiles>
</properties>
</profile>
<!-- ... and (outside/in default profile!) -->
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<!-- ... -->
</build>
spring.profiles.active=${myProfiles}
spring.profiles.active=local,foo,bar
-----------------------
-Dspring.profiles.active=local
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dspring.profiles.active=local</argLine>
</configuration>
</plugin>
<profile>
<id>local</id>
<properties>
<myProfiles>local,foo,bar</myProfiles>
</properties>
</profile>
<!-- ... and (outside/in default profile!) -->
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<!-- ... -->
</build>
spring.profiles.active=${myProfiles}
spring.profiles.active=local,foo,bar
-----------------------
-Dspring.profiles.active=local
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dspring.profiles.active=local</argLine>
</configuration>
</plugin>
<profile>
<id>local</id>
<properties>
<myProfiles>local,foo,bar</myProfiles>
</properties>
</profile>
<!-- ... and (outside/in default profile!) -->
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<!-- ... -->
</build>
spring.profiles.active=${myProfiles}
spring.profiles.active=local,foo,bar
-----------------------
-Dspring.profiles.active=local
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dspring.profiles.active=local</argLine>
</configuration>
</plugin>
<profile>
<id>local</id>
<properties>
<myProfiles>local,foo,bar</myProfiles>
</properties>
</profile>
<!-- ... and (outside/in default profile!) -->
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<!-- ... -->
</build>
spring.profiles.active=${myProfiles}
spring.profiles.active=local,foo,bar
-----------------------
-Dspring.profiles.active=local
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dspring.profiles.active=local</argLine>
</configuration>
</plugin>
<profile>
<id>local</id>
<properties>
<myProfiles>local,foo,bar</myProfiles>
</properties>
</profile>
<!-- ... and (outside/in default profile!) -->
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<!-- ... -->
</build>
spring.profiles.active=${myProfiles}
spring.profiles.active=local,foo,bar
QUESTION
How to search for latest file in folder and if not found then open dialog box with restrictions
Asked 2022-Apr-08 at 14:28So basically the goal is to combine these to functions into one or make it compatible with each other cause atm there is errors when it comes to the part when the path of the chosen file is not refer to in the same manner as the path of the found file within the loop if available in the folder.
So I know why I'm getting the error please see below 'HERE IS WHERE I GET THE ERROR' but I cant write the proper code to find my way out of the situation.
'main code that run is doing something like search for file within folder,
'loop and get the latest file and generates a path and name for next
'function which is to copy a sheet from the found file over to the main
'workbook and so.
'What I'm trying to to is to build a failsafe, lets say file is not pushed
'or placed whin this predestinated folder, then instead of doing nothing,
'dialog box opens up and files gets chosen instead.
Option Explicit
Sub ImportAndFormatData()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Const sFolderPath As String = "C:\Temp\"
'Search for newest file
Dim sFileName As String: sFileName = Dir(sFolderPath & "_pr11*.xlsx")
If Len(sFileName) = 0 Then Call OpenDialogBox
Dim cuDate As Date, sFileDate As Date, cuPath As String, sFilePath As String
Do Until Len(sFileName) = 0
cuPath = sFolderPath & sFileName
cuDate = FileDateTime(cuPath)
'Debug.Print "Current: " & cuDate & " " & cuPath ' print current
If cuDate > sFileDate Then
sFileDate = cuDate
sFilePath = cuPath
End If
sFileName = Dir
Loop
'Debug.Print "Result: " & sFileDate & " " & sFilePath ' print result
'Open newest file - HERE IS WHERE I GET THE ERROR
Dim closedBook As Workbook: Set closedBook = Workbooks.Open(sFilePath)
closedBook.Sheets("Analyse").Copy After:=ThisWorkbook.Sheets("PR11_P3")
closedBook.Close SaveChanges:=False
'code dose not end here but that part don't need to be included here since
'its just formatting
End Sub
And here is function for OpenDialogBox, I'm tying to enforce just a specific titel (cause only this file/rapport is correct source for the entire code (or rather rest of the code) but I cant figure this part out either, please see below, GIVES ERROR DOSENT WORK)
Sub OpenDialogBox()
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Filters.Clear
.Title = "Välj valfri PR11"
.Filters.Add "Excel filer", "_pr11*.xlsx?", 1 'GIVES ERROR DOSENT WORK
.AllowMultiSelect = False
If .Show = True Then
Debug.Print .SelectedItems(1)
Debug.Print Dir(.SelectedItems(1))
End If
End With
End Sub
ANSWER
Answered 2022-Apr-08 at 14:28This combines both the Dir()
and FileDialog
approaches:
Sub ImportAndFormatData()
Dim fSelected As String, wb As Workbook
fSelected = InputFile()
If Len(fSelected) > 0 Then
Set wb = Workbooks.Open(fSelected)
wb.Sheets("Analyse").Copy After:=ThisWorkbook.Sheets("PR11_P3")
wb.Close False
End If
End Sub
Function InputFile() As String
Const SRC_FOLDER As String = "C:\Temp\"
Dim f, fSelected As String, latestDate As Date, fdt
f = Dir(SRC_FOLDER & "*_pr11*.xlsx") 'first check the configured folder for a match
If Len(f) > 0 Then
'found matching file at specified path: loop for the newest file
Do While Len(f) > 0
fdt = FileDateTime(SRC_FOLDER & f)
If fdt > latestDate Then
fSelected = SRC_FOLDER & f
latestDate = fdt
End If
f = Dir()
Loop
InputFile = fSelected
Else
'no match at specified path - allow user selection
With Application.FileDialog(msoFileDialogFilePicker)
.Filters.Clear
.Title = "Välj valfri PR11"
.Filters.Add "Excel filer", "*.xlsx" 'filter only allows extension: no filename wildcards...
.AllowMultiSelect = False
If .Show Then InputFile = .SelectedItems(1)
End With
End If
End Function
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit