Tuesday, November 24, 2020

Macro to Change the Font/Color/Size/Alignment of Text Box content PowerPoint

Macro code to ease your manual work, if you have large number of slides in your presentation and globally want to change the property of text then below code is helpful.

You can change the Font Size, Font Color, Font Property like  Bold, Italic, underline, Font Type, Shadow and many more

Use below code in Power Point file and execute below macro code

Sub TextSize()
Dim oSl As Slide
Dim oSh As Shape
With ActivePresentation
For Each oSl In .Slides
For Each oSh In oSl.Shapes
With oSh
If .HasTextFrame Then
If .TextFrame.HasText Then
.TextFrame.TextRange.Font.Size = 48
.TextFrame.TextRange.Font.Color = RGB(112, 48, 160)
.TextFrame.TextRange.Font.Italic = msoTrue
.TextFrame.TextRange.Font.Name = "Brush Script MT"
.TextFrame.TextRange.Font.Shadow = msoTrue
.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
End If
End If
End With
Next
Next
End With
End Sub

Macro Code to Copy Content from Excel File to PowerPoint, Each Row to Each Slide

Requirement
1. Need to Copy data from Excel Column A, to Power Point
2. Row 1 data Go to Slide 1
3. Row 2 data will go to Slide 2
4. Row 3 data will go to slide 3


PreRequisite
  • I have some content in Excel in Column "A"
  • Column "A", have at least 1 record in cell A1 and can have any number of records in row
  • Must have PowerPoint file with you 
  • Decide your template before hand
  • You must have slides ready in PowerPoint
  • Number of Slides must be Equal to the number of Row in Excel , which need to Copy over
  • Below Macro Code need to be execute in Excel
    1. Click on Macro
    2. Type any Name and Click on "Create" button
    3. New Popup will be there and Copy Paste Below Macro Code (Replace existing Sub/End Sub) and Save 
  • Run Code
  • On Successful execution of code, PowerPoint file will Open and Close
  • Only PowerPoint without any file stay Open, If yes Close it manually
  • On VB window, you can see the dialog box "Done"
  • If yes your code executed without any error

Sub ExcelRowtoPPT()
    Dim sht As Worksheet
    Dim PPApp As PowerPoint.Application
    Dim PPShape As PowerPoint.Shape
    Dim PPPresentation As PowerPoint.Presentation
    Dim PPTSlide As Slide
    Dim V_PPTPath As String
Dim V_PPTPath_New As String
    V_PPTPath = "C:\Users\UserName\Desktop\macro\Presentation1.pptx"
    V_PPTPath_New = "C:\Users\UserName\Desktop\macro\Presentation1.pptx"
    Set PPApp = CreateObject("PowerPoint.Application")
    PPApp.Visible = msoTrue
    Set PPPresentation = PPApp.Presentations.Open(V_PPTPath)
    For Each PPTSlide In PPPresentation.Slides
        i = PPTSlide.SlideNumber
Set sht = Worksheets("Sheet1")
        sht.Activate
        Dim S2 As String
        Dim Cellname As String
        Cellname = "A" & i
            sht.Range(Cellname).Copy
            PPTSlide.Shapes.Paste
             With PPApp
                .ActiveWindow.Selection.ShapeRange.Align msoAlignTops, True
                .ActiveWindow.Selection.ShapeRange.Top = 350
                .ActiveWindow.Selection.ShapeRange.Left = 650
                .ActiveWindow.Selection.ShapeRange.Width = 400
             End With
        Application.ScreenUpdating = True
    Next
    PPApp.Activate
    PPPresentation.SaveAs V_PPTPath_New
    PPPresentation.Close
    PPApp.Quit
    Set PPShape = Nothing
    Set PPPresentation = Nothing
    Set PPApp = Nothing
    MsgBox "Done", vbOKOnly + vbInformation
End Sub


You might face clipboard Error while executing the above code, if you are still facing the error then try to re-execute the code by 2 or 3 times.

Monday, November 23, 2020

VB : run time error 429: ActiveX component can't create object

Error

run time error 429:

ActiveX component can't create object

After Having the Change from the Original Post 

To resolve error in code i used "Late Binding", then i did a attempt after few days on same work then facing a new error related to "ActiveX"

Again did some research and people/developer suggest different type of solutions but issue is straight forward.

In code you are using component of library which is not selected in reference for VBA

Solution
Note * - Your code should not in execution mode
note * - Change your code to original if you also had used "late binding"
1. Open VB
2. Go to "Tools"
3. Reference > you can see the popup "References VBAProject"
4. Scroll Down and select the required Library
**In my case I haven't selected the PowerPoint Library
so select "Microsoft PowerPoint 16.0 Object Library"
5. Go back and execute your code

VB : Compile Error: User Defined Datatype not defined

I was executing macro Code and trying to access excel and powerpoint file from the macro code. While executing the macro Code getting below error :

Compile Error: 

User Defined Datatype not defined

Here are the few lines of the Macro Code:

Dim V_Excel As Excel.Application
Dim v_book As Excel.Workbook
Dim v_sheet As Excel.Worksheet
Dim v_ppt As Presentation
Dim v_slide As Slide


Solution
After doing the R&D, getting the result from google that this problem can be solved using late binding methods

Dim V_Excel As Object
Set V_Excel = CreateObject("Excel.Application")
Dim v_book As Object
Set v_book  = CreateObject("Excel.Workbook")
Dim v_sheet As Object
Set v_sheet  = CreateObject("Excel.Worksheet")
Dim v_ppt As Object
Set v_ppt  = CreateObject("Presentation")
Dim v_slide As Object
Set v_slide = CreateObject("Slide")

Friday, November 20, 2020

ORA-12899: value too large for column ColumnName

Error  :
. . imported "DatabaseName"."TableName"                   171.3 KB    5789 rows
ORA-02374: conversion error loading table "DatabaseName"."TableName"
ORA-12899: value too large for column ColumnName (actual: 31, maximum: 30)
ORA-02372: data for row: ColumnName : 0X'5467ASH567UJGFRT4VXH567HFGHK5EWHD57GQ5'

You are trying to restore the database with IMPDP command, sometimes you will receive the error in logs, ORA-12899: value too large for column Column Name

If you faced this error too, then solve as below:

  1. Check the table name and column name from the logs, for which this error occur
  2. After restore complete alter the table and increase the size of column (using alter command)
  3. Again execute the IMPDP command for specific table only and include the below 3 parameter in your IMPDP command

Use below 3 parameter in your IMPDP command, see below parameter and description

  • remap_Table - Specify which table need to map with existing table
  • tables - Specify, which particular table need to restore
  • table_exists_action - Specify, what should be the action if table already exists, these are of 4 type  {SKIP | APPEND | TRUNCATE | REPLACE}, for more information you can read official website


use below parameter along with the usage, see below:

  • remap_Table = OldTableName_InBackup:NewdatabasetableName
  • tables = TypeYourTableNameHere
  • table_exists_action=Truncate

See full IMPDP command here (Click Here)

ORA-39151: Table "DatabaseName"."TableName" exists.

Error
ORA-39151: Table "DatabaseName"."TableName" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Problem :

1. you might be trying to restore database using IMPDP command and in IMPDP using existing database to restore and used "remap_Table" in your IMPDP command

2. You might try to restore single table using "remap_Table" paramter


Solution:

Use below 3 parameter in your IMPDP command, see below parameter and description

  • remap_Table - Specify which table need to map with existing table
  • tables - Specify, which particular table need to restore
  • table_exists_action - Specify, what should be the action if table already exists, these are of 4 type. {SKIP | APPEND | TRUNCATE | REPLACE}, for more information you can read official website

use below parameter along with the usage, see below:

  • remap_Table = OldTableName_InBackup:NewdatabasetableName
  • tables = TypeYourTableNameHere
  • table_exists_action=Truncate

Restore Table From Full Backup

Scenario is you have database/User already exists and received a new Database Backup and you want to restore only 1 table instead of full database restore. And you want to restore table in existing database/User. So you need to use 3 new parameters in your existing restore IMPDP command. These are as below:

  • remap_Table
  • tables
  • table_exists_action
Full IMPDP command

impdp 
DIRECTORY=DirectoryName
DUMPFILE=Backupname.DMP 
LOGFILE=AnyFileName.log 
PARALLEL=8 
EXCLUDE=INDEX 
remap_schema=OldUser_Inbackup:NewUser
remap_tablespace=OldTablespace_Inbackup:NewTablespace
exclude=statistics
--New Paramaters
remap_Table = OldTableName_InBackup:NewdatabasetableName
tables = TypeYourTableNameHere
table_exists_action=Truncate

Tuesday, November 17, 2020

Talend Start Up Error : An error occurred while automatically activating bundle org.talend.designer.core (1557).


This error generated in log file of Talend during startup of talend job. 

!SESSION 2020-11-11 12:35:58.951 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_271
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Command-line arguments:  -os win32 -ws win32 -arch x86_64
 
This is a continuation of log file D:\Talend_Integration\TOS-Win32-r30698-V3.2.0\workspace1\.metadata\.bak_0.log
Created Time: 2020-11-11 12:35:59.910
!SESSION 2020-11-11 12:35:58.951 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_271
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Command-line arguments:  -os win32 -ws win32 -arch x86_64
 
!ENTRY org.eclipse.osgi 4 0 2020-11-11 12:35:59.911
!MESSAGE An error occurred while automatically activating bundle org.talend.designer.core (1557).
!STACK 0
org.osgi.framework.BundleException: The activator org.talend.designer.core.DesignerPlugin for bundle org.talend.designer.core is invalid


Issue
Previous Talend was working, suddenly after weekend restart, Talend stop working

Problem
Java got updated during restart

Solution
Start Talend UI by pointing to specific JDK installed previously. 

Use Command (run in CMD): 
  • TOS_DI-win32-x86.exe -vm "C:\Program Files (x86)\Java\jdk1.7.0_65\bin"

Semicolon, comma separated data to Rows

 If you have data in column in comma separated or semicolon separated and you would like to separate each one to a new row, it is pretty simple in SQL server. Use below query as per your requirement, right now this query is looking for semicolon as separator, and you modify the query as per requirement. Change the column names as per your table structure.


;WITH temp(ID, Newcolumn, Name) AS

(
    SELECT
        Id,
cast(LEFT(Name, CHARINDEX(';', Name + ';') - 1) as nvarchar(2000)),
        STUFF(Name, 1, CHARINDEX(';', Name + ';'), '')
    FROM 
YOURTABLENAME
where 
name like '%;%'
    UNION all
    SELECT
        Id,
cast(LEFT(Name, CHARINDEX(';', Name + ';') - 1) as nvarchar(2000)),
        STUFF(Name, 1, CHARINDEX(';', Name + ';'), '')
    FROM 
temp
    WHERE
        Name > ''
)
SELECT
    Newcolumn 
FROM 
temp
 


Do not change the column name "Newcolumn" from query, as this column is key column for your query. will store all new data in this column.

how table data looks like for me:

YOURTABLENAME
id      Name
1       Andhra Pradesh; Arunachal Pradesh; Assam; Bihar; Chhattisgarh; Goa; Gujarat; Haryana; Himachal Pradesh; Jammu and Kashmir; Jharkhand; Karnataka; Kerala; Madhya Pradesh; Maharashtra; Manipur; Meghalaya; Mizoram; Nagaland; Odisha; Punjab; Rajasthan; Sikkim; Tamil Nadu; Telangana; Tripura; Uttar Pradesh; Uttarakhand; West Bengal; Andaman and Nicobar; Chandigarh; Dadra and Nagar Haveli; Daman and Diu; Lakshadweep; Delhi; Puducherry
2       Alabama;  Alaska;  American Samoa;  Arizona;  Arkansas;  California;  Colorado;  Connecticut;  Delaware;  District of Columbia;  Florida;  Georgia;  Guam;  Hawaii;  Idaho;  Illinois;  Indiana;  Iowa;  Kansas;  Kentucky;  Louisiana;  Maine;  Maryland;  Massachusetts;  Michigan;  Minnesota;  Minor Outlying Islands;  Mississippi;  Missouri;  Montana;  Nebraska;  Nevada;  New Hampshire;  New Jersey;  New Mexico;  New York;  North Carolina;  North Dakota;  Northern Mariana Islands;  Ohio;  Oklahoma;  Oregon;  Pennsylvania;  Puerto Rico;  Rhode Island;  South Carolina;  South Dakota;  Tennessee;  Texas;  U.S. Virgin Islands;  Utah;  Vermont;  Virginia;  Washington;  West Virginia;  Wisconsin;  Wyoming


How data will appear after executing query

1 Andhra Pradesh
1 Arunachal Pradesh
1 Assam
1 Bihar
1 Chhattisgarh
1 Goa
1 Gujarat
1 Haryana
1 Himachal Pradesh
1 Jammu and Kashmir
1 Jharkhand
1 Karnataka
1 Kerala
1 Madhya Pradesh
1 Maharashtra
1 Manipur
1 Meghalaya
1 Mizoram
1 Nagaland
1 Odisha
1 Punjab
1 Rajasthan
1 Sikkim
1 Tamil Nadu
1 Telangana
1 Tripura
1 Uttar Pradesh
1 Uttarakhand
1 West Bengal
1 Andaman and Nicobar
1 Chandigarh
1 Dadra and Nagar Haveli
1 Daman and Diu
1 Lakshadweep
1 Delhi
1 Puducherry
2 Alabama
2 Alaska
2 American Samoa
2 Arizona
2 Arkansas
2 California
2 Colorado
2 Connecticut
2 Delaware
2 District of Columbia
2 Florida
2 Georgia
2 Guam
2 Hawaii
2 Idaho
2 Illinois
2 Indiana
2 Iowa
2 Kansas
2 Kentucky
2 Louisiana
2 Maine
2 Maryland
2 Massachusetts
2 Michigan
2 Minnesota
2 Minor Outlying Islands
2 Mississippi
2 Missouri
2 Montana
2 Nebraska
2 Nevada
2 New Hampshire
2 New Jersey
2 New Mexico
2 New York
2 North Carolina
2 North Dakota
2 Northern Mariana Islands
2 Ohio
2 Oklahoma
2 Oregon
2 Pennsylvania
2 Puerto Rico
2 Rhode Island
2 South Carolina
2 South Dakota
2 Tennessee
2 Texas
2 U.S. Virgin Islands
2 Utah
2 Vermont
2 Virginia
2 Washington
2 West Virginia
2 Wisconsin
2 Wyoming

Monday, November 2, 2020

Concatenate Rows in SQL Server

In SQL Server if you would like to concatenate row to 1 single string, with using stuff, XML path aggregation, alternatively we can use T/SQL program.

I am preferring the TSQL cause of few reasons, first reason as before i was using XML Path aggregation and while using that method string truncation occurs at some limit. XML Path/stuff was not able to aggregate or concatenate all rows from table in single row.

Either we need to limit the number of rows while using above way.

in TSQL we can handle this situation, in that way we can play with length of charaters that need to concatenate.

How to use below TSQL:

first you guys need to populate your data in below table format, table name and column name should be exactly same.
Table Name - Table_Group
Column Name 1 - Column_id (will be using for group by )
Column Name 2 - column_text (that need to concatenate)


IF exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'data' AND TABLE_SCHEMA = 'dbo')
Drop table dbo.data;
create table data (id int, content nvarchar(max))

Declare
@out1 VARCHAR(max),
@Query_Part1 VARCHAR(max), 
@Query_Part2 VARCHAR(max), 
@Query_Part3 VARCHAR(max),
@Query_Part4 VARCHAR(max),
@Query_Final VARCHAR(max),
@row_num int
Declare
@column_id VARCHAR(400), 
@column_text VARCHAR(max) ,
@n int
set @Query_Part1 = '';
set @Query_Part2 = '';
set @Query_Part3 = '';
set @Query_Part4 = '';
set @Query_Final = '';
set @n = 0;
set @row_num = 0;
DECLARE CURSOR_C1 CURSOR FOR SELECT distinct column_id  FROM Table_Group  order by 1
OPEN CURSOR_C1
FETCH NEXT FROM CURSOR_C1 INTO @column_id 
WHILE @@FETCH_STATUS=0
BEGIN
DECLARE CURSOR_C2 CURSOR FOR 
SELECT column_text, row_number() over (order by column_id ) rn FROM Table_Group where column_id  = @column_id order by 2
OPEN CURSOR_C2
FETCH NEXT FROM CURSOR_C2 INTO @column_text , @row_num
WHILE @@FETCH_STATUS=0
BEGIN
IF isnull(LEN(@Query_Part2),0) < 1 AND (isnull(LEN(@Query_Part1),0) + isnull(len(@column_text),0)  ) < 32767 
set @Query_Part1 = @Query_Part1 + char(10)+ '-Line  ' +cast(@row_num as nvarchar)+ ' - '+char(10) +@column_text 
ELSE IF isnull(LEN(@Query_Part3),0) < 1 AND (isnull(LEN(@Query_Part2),0) + isnull(len(@column_text),0) ) < 32767 
set @Query_Part2 = @Query_Part2 +char(10)+ '-Line  ' +cast(@row_num as nvarchar)+ ' - '+char(10)  +@column_text 
ELSE IF isnull(LEN(@Query_Part4),0) < 1 AND (isnull(LEN(@Query_Part3),0)  + isnull(len(@column_text),0)) < 32767 
set @Query_Part3 = @Query_Part3 + char(10)+ '-Line  ' +cast(@row_num as nvarchar)+ ' - '+char(10)  +@column_text 
ELSE
set @Query_Part4 = @Query_Part4 +char(10)+ '-Line ' +cast(@row_num as nvarchar)+ ' - ' +char(10) +@column_text 
set @Query_Final = isnull(@Query_Part1,'')+isnull(@Query_Part2,'')+isnull(@Query_Part3,'')+isnull(@Query_Part4,'')
--print @Query_Final
FETCH NEXT FROM CURSOR_C2 INTO @column_text , @row_num
END
CLOSE CURSOR_C2;
DEALLOCATE CURSOR_C2;
insert into data values ( @column_id , @Query_Final) ;
set @Query_Final = ''
set @Query_Part1 = ''
set @Query_Part2 = ''
set @Query_Part3 = ''
set @Query_Part4 = ''
FETCH NEXT FROM CURSOR_C1 INTO @column_id;
set @row_num = 0 ;
END
CLOSE CURSOR_C1;
DEALLOCATE CURSOR_C1;
select *from data
web stats