How to lose the focus of the selected cells when it is done with the 'Clipboard.Clear()' command in Visual Basic?

Mansour_Dalir 1,571 Reputation points
2024-04-18T17:02:16.4433333+00:00

User's image

hi

   Private Sub tsmFillNumberMerged_Click(sender As Object, e As EventArgs) Handles tsmFillNumberMerged.Click
        'Trying to (Fill Auto Namber) cells when they are merging
        If Clipboard.GetText IsNot Nothing Then
            Dim sttClip As String = Clipboard.GetText()
            Dim spl1 As String() = Split(sttClip, vbNewLine)
            Dim pStart As Integer = InputBox("Set Start At ? ", DefaultResponse:=1)
            Dim sttResult As String = ""
            For Each pLine As String In spl1
                If pLine = "" Then
                    sttResult += vbNewLine
                Else
                    sttResult += pStart & vbNewLine
                    pStart += 1
                End If
            Next
            Application.DoEvents()
            Clipboard.Clear() ' Sometimes it works randomly and sometimes it doesn't
            Application.DoEvents()
            Clipboard.SetText(sttResult) ' not Set On Clipboard
            '  MsgBox("Clipboard is Ready . Paste Into Excel .Copy the Pasted Values Again Then On the first Merged Cell Of the [Paste Option] Click On Paste Link")
        End If
    End Sub
Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,468 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,575 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,500 questions
0 comments No comments
{count} votes